October 13, 201510 yr 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: 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 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?
October 13, 201510 yr Here are the commands in hex: POP00: 50 4f 50 30 30 c2 48 0d POP02: 50 4f 50 30 32 e2 0b 0dQPIGS: 51 50 49 47 53 b7 a9 0dQPIRI: 51 50 49 52 49 f8 54 0d This example program works with my inverter: https://github.com/scottwday/AxpertTest/blob/master/Program.cs
October 14, 201510 yr //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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.