On Apr 26, 2007, at 09:01 UTC, Gregory Omond wrote: > Sorry that I am such a "basic newbie"... I have dabbled a bit in C > and assembler and Delphi on PC, But now I am in Mac land (sick of > viruses).
Welcome! :) > All messages constructed according to the following format: > > Byte Contents > 0 Start-Mark (SOH,01hex) > 1 Destination Address > 2 Source Address > 3 Message-Code > 4 Data-Length > 5 Data-Field(1) > N+4 Data-Field(N) > N+5 CRC-Field(1) (MS Byte) > N+6 CRC-Field(2) > N+7 End-Mark(EOT, 04hex) The easiest way to construct something like this is to use a MemoryBlock. Something like this: Dim mb as New MemoryBlock( data.LenB + 8 ) mb.Byte(0) = &h01 // SOH mb.Byte(1) = destAddress mb.Byte(2) = srcAddress mb.Byte(3) = messageCode mb.Byte(4) = data.LenB mb.StringValue(5,data.LenB) = data mb.Byte(data.LenB+5) = crcField1 mb.Byte(data.LenB+6) = crcField2 mb.Byte(data.LenB+7) = &h04 // EOT Serial1.Write mb That last step works because RB implicitly converts a MemoryBlock to a string (and vice versa). So even though Serial.Write expects a string, you can pass it a MemoryBlock and it just sends the whole contents thereof. > I tried the following: > > Sub Action > > Serial1.SerialPort.OutputDriverName.Encoding.variant 0x00 I'm not sure what you were trying to accomplish with this. It's not needed anyway. > Serial1.Write 0x01 0x01 isn't RB syntax; in RB that'd be &h01. But that won't work with Serial.Write, because that needs a string, not an integer. To do this byte by byte, you would do: Serial1.Write ChrB(&h01) ChrB converts an integer 0-255 to the corresponding string containing that byte. But the MemoryBlock technique above is much simpler in this case. Best, - Joe -- Joe Strout -- [EMAIL PROTECTED] _______________________________________________ Unsubscribe or switch delivery mode: <http://www.realsoftware.com/support/listmanager/> Search the archives: <http://support.realsoftware.com/listarchives/lists.html>
