scottwday
Members
-
Joined
-
Last visited
Reputation Activity
-
scottwday got a reaction from Paul.Chari in Axpert 5KVA Watchpower monitoring softwareYou have sp.Open commented out as well.
I've put a simple C# command line utility on my github which lets you send a command and prints out the response.
It handles all the CRC stuff. It might also be useful for anyone wanting to use it from scripts etc.
Eg:
console>AxpertTest -p COM3 QPI(PI30console>AxpertTest -p COM3 QPIGS(244.2 49.9 244.2 49.9 0024 0015 000 435 54.00 001 100 0019 0000 000.0 00.00 00000 00010101 00 00 00000 110 You can also set the baud (- and the timeout in milliseconds (-t)
Here'e the .exe binary
https://drive.google.com/file/d/0B8CTDo4cVxUlYzFZWnYtYlVETFE/view?usp=sharing
Here's the sourcecode
https://github.com/scottwday/AxpertTest/blob/master/Program.cs
I've tested it works on my inverter (~2014 model) and with my emulator
-
scottwday got a reaction from Warren in Axpert 5KVA Watchpower monitoring softwarehttps://github.com/scottwday/AxpertTest
-
scottwday got a reaction from Warren in Axpert 5KVA Watchpower monitoring softwareThe line will always end with a CR character. There will never be a CR in the CRC, so as soon as you get a 0x0d you know you've got the entire response.
static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e) { var sp = sender as SerialPort; if ((sp != null) && (!_gotResponse)) { //Read chars until we hit a CR character while (sp.BytesToRead > 0) { byte b = (byte)sp.ReadByte(); _rxBuffer.WriteByte(; if (b == 0x0d) { _gotResponse = true; break; } } } } -
scottwday got a reaction from Warren in Axpert 5KVA Watchpower monitoring softwareThe inverter will only reply once it receives a CR (0x0d) character.
The last argument to SerialPort.Write is the number of bytes to write. you're always going to need to write more than 2 bytes. In fact it's always going to be 3 more bytes than the command you want to send:
The format is <command><CRC_MSB><CRC_LSB><CR>
public byte[] GetBytes(string Command, ushort Crc){ byte[] result = new byte[Command.Length + 3]; Encoding.ASCII.GetBytes(Command, 0, Command.Length, result, 0); result[result.Length - 3] = (byte)((Crc >> 8) & 0xFF); result[result.Length - 2] = (byte)((Crc >> 0) & 0xFF); result[result.Length - 1] = 0x0d; return result;} This code packs the bytes to send. First it's the bytes from a string, then 2 bytes of the 16 bit CRC, then a CR character.
If you look at the CRC code it makes sure that it never uses 0x0d or 0x0a because they are characters that denote the end of the command.