Andrew Bestic Posted April 11, 2013 Report Share Posted April 11, 2013 I'm trying to write values and I'm not sure what the binary WRITE message format is, in relation to the READ message format. I couldn't find this answered in the PDF or on the forums yet. I read a summary in the PDF that byte 12 should be changed to 68 and the write values should be appended to byte 32 (which confused me further as that's after the footer checksum). This is what I have for READ: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 24 25 26 27 28 29 | 30 31 32 stx-------------- id FE 01 00 00 00 cn 00 specific--------- lengt chksm | numbr ot FF addr- | chksm ex What would be the correct format for WRITE? Quote Link to comment Share on other sites More sharing options...
Saragani Posted April 18, 2013 Report Share Posted April 18, 2013 The document on our website describes how to read values in Binary Protocol. The documented command is only useful for reading (while writing is still in ASCII). However, few years ago we have added a new command that allows you to read and write using Binary Command (And this command actually allows you have a read and write request on the same command). This command is not documented on our website, but if you know C# then you can take the .Net communication driver sources (which are available on our website) and understand the structure of the command. 1 Quote Link to comment Share on other sites More sharing options...
Andrew Bestic Posted April 23, 2013 Author Report Share Posted April 23, 2013 Thanks. Do you have any specifics on where that command is? I have Unitronics.ComDriver source but I'm not the most proficient at C# so any information on locating related methods would be hugely helpful. Quote Link to comment Share on other sites More sharing options...
Andrew Bestic Posted April 23, 2013 Author Report Share Posted April 23, 2013 Please ignore my unapproved post. I found some related information in BinaryMessage.cs and WriteOperand.cs. I'm not very proficient at C# but I noticed there are a lot of variables at play, making it difficult for me to narrow down an actual command string. Do you have specifics on which methods or strings I should be referring to? Quote Link to comment Share on other sites More sharing options...
Saragani Posted April 23, 2013 Report Share Posted April 23, 2013 You should look for the FullBinaryMixExecuter The command code should be 80 I'm attaching a document I've written few years back about the Full Binary Mix protocol Full Binary Mix.pdf Quote Link to comment Share on other sites More sharing options...
Andrew Bestic Posted April 24, 2013 Author Report Share Posted April 24, 2013 Thank you, that's come in handy. Now I'm onto writing specific operands, I have gotten MB and MI working (reading and writing), ML, MF, DW (reading only). I'm not sure what the method for writing those last 3 are, I know that I have to reverse the byte order for MIs, is it similar for MLs? I'm assuming that ML is 4 hex bytes and DW is 6. I have to write this for every operand type. I'm still running through the C# in relation to those. Quote Link to comment Share on other sites More sharing options...
Saragani Posted April 24, 2013 Report Share Posted April 24, 2013 I don't remember anything of reversing the byte order of MIs, or any operand (maybe Float), here is a code from the .Net communication driver that takes the value and convert it to bytes: private IEnumerable<byte> AddWriteData(object[] writeData, byte writeOperandId) { List<byte> results = new List<byte>(); string operandName = writeOperandId.GetOperandNameByValueForFullBinary(); switch (operandName) { case "MB": case "SB": case "XB": case "INPUT": case "Output": case "TimerRunBit": case "CounterRunBit": case "RTC": foreach (object value in writeData) { UInt16 bitValue = BitConverter.ToUInt16(BitConverter.GetBytes(Convert.ToSByte(value)), 0); if (bitValue > 0) results.Add(1); else results.Add(0); if (writeData.Length == 1) results.Add(0); } break; case "MI": case "SI": case "XI": case "CounterCurrent": case "CounterPreset": foreach (object value in writeData) { results.AddRange(BitConverter.GetBytes(Convert.ToInt16(value))); } break; case "ML": case "SL": case "XL": foreach (object value in writeData) { results.AddRange(BitConverter.GetBytes(Convert.ToInt32(value))); } break; case "TimerCurrent": case "TimerPreset": foreach (object value in writeData) { if (value.GetType().Equals(typeof(List<UInt16>))) results.AddRange(BitConverter.GetBytes(Utils.z_GetSecondsValue(value as List<UInt16>))); else results.AddRange(BitConverter.GetBytes(Convert.ToUInt32(value))); } break; case "MF": foreach (object value in writeData) { //Switch to IEEE 754 standard byte[] floatBytes = BitConverter.GetBytes(Convert.ToSingle(value)); Array.Reverse(floatBytes, 0, 4); Array.Reverse(floatBytes, 0, 2); Array.Reverse(floatBytes, 2, 2); results.AddRange(floatBytes); } break; case "DW": case "SDW": case "XDW": foreach (object value in writeData) { results.AddRange(BitConverter.GetBytes(Convert.ToUInt32(value))); } break; } return results; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.