Jump to content

Calling all programmers - help!


edmundp

Recommended Posts

Hi All,

 

Need some advice as I am stumped/stupid. I am trying to fiddle around in C# to call the inverter with certain commands. I got the basics going and get the NAK response. (Been a LONG time since I programmed so snails pace.)

 

The problems are as follows:

 

  1. Could someone please help me with the fixed CRC codes to send for the following commands - I know they are calculated but after that remains the same:
    • POP00 = Run off Utility
    • POP02 = Run off Batteries
    • QPIGS
    • QPIRI
  2. How on earth do I send these CRC values to the serial port in C# - I have tried serialport.write (send string & hex byte, serialport.writeline (send string as hex translated to char) etc.

I get the NAK response if using serialport.writeline("QPIGS") - that obviously should not work, but that proves the port is open and readable.

 

Please?

Link to comment
Share on other sites

//TO SENDSerialPort sp = new SerialPort(); sp.PortName = "COM3";            sp.BaudRate = 2400;            sp.DataBits = 8;            sp.Parity = Parity.None;            sp.StopBits = StopBits.One;            sp.Open();            sp.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);            sp.ErrorReceived += new SerialErrorReceivedEventHandler(DataErrorReceivedHandler);            ProtocolCommand.command = "QPI";            byte[] tx = ProtocolCommand.GetBytes(Encoding.ASCII.GetString(ProtocolCommand.QPI),                        CRC16.Calculate(Encoding.UTF8.GetBytes(Encoding.ASCII.GetString(ProtocolCommand.QPI))));            sp.Write(tx, 0, tx.Length);//RECIEVE RESPONSESpublic void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)        {            var sp = sender as SerialPort;            MemoryStream _rxBuffer = new MemoryStream();            bool _gotResponse = false;            if ((sp != null) && (!_gotResponse))            {                while (sp.BytesToRead > 0)                {                    byte b = (byte)sp.ReadByte();                    _rxBuffer.WriteByte(;                    if (b == 0x0d)                    {                        _gotResponse = true;                        break;                    }                }            }            _gotResponse = false;            _rxBuffer.Position = 0;            SetText(Encoding.ASCII.GetString(_rxBuffer.ToArray()));            Datalogger.insertRecord(ProtocolCommand.command, Encoding.ASCII.GetString(_rxBuffer.ToArray()));            _rxBuffer.Dispose();        }

Hope this helps :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...