Re: [DUG] HEX to decimal
I was meaning to look at some code I have for doing a similar thing, but glad you got it sorted. The stopbits wouldn't have been helpful :-) Its much easier to spot that sort of thing when its just text, but when its binary its a bit more difficult :-) Jeremy -Original Message- From: delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] On Behalf Of Marshland Engineering Sent: Monday, 8 August 2011 13:06 To: delphi@delphi.org.nz Subject: Re: [DUG] HEX to decimal I finally got it working. The number of stop bits was wrong, that's why the first character was always correct and the rest incorrect. Final code if SerialPortNG.NextClusterSize = 0 then begin sRaw:=SerialPortNG.ReadNextClusterAsString; for i:=1 to length(sRaw) do iData[i]:= byte(sRaw[i]); Thanks Wallace ___ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe ___ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe
Re: [DUG] HEX to decimal
I finally got it working. The number of stop bits was wrong, that's why the first character was always correct and the rest incorrect. Final code if SerialPortNG.NextClusterSize = 0 then begin sRaw:=SerialPortNG.ReadNextClusterAsString; for i:=1 to length(sRaw) do iData[i]:= byte(sRaw[i]); Thanks Wallace ___ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe
Re: [DUG] HEX to decimal
edit2.text := IntToStr(StrToInt('$' + sRaw)); On Thu, Aug 4, 2011 at 5:50 PM, Marshland Engineering marshl...@marshland.co.nz wrote: ** I cannot get the decimal equivalent of the number sent from my micro in Delphi !!! I am running and ATmega (micro) and it sends out a hex number corresponding to an A to D conversion. It is 8 bit. I'm using SerialNG to read the data with procedure TfDyno.SerialPortNGRxClusterEvent(Sender: TObject); Var sRaw:String; begin if SerialPortNG.NextClusterSize = 0 then begin sRaw:=SerialPortNG.ReadNextClusterAsString; edit2.text:=sRaw; end; end; In the text box I get the ASCII character displayed eg [ { 9 * { } % etc. How do I get the Decimal equivalent to display. Should be in the range 0-65534. I've spent many hours trying so far !!! Cheers Wallace ___ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe ___ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe
Re: [DUG] HEX to decimal
Been there done that edit2.text := IntToStr(StrToInt('$' + sRaw)); Result '[' is not a valid integer. ___ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe
Re: [DUG] HEX to decimal
You might need to use the ORD function byte by byte Steven From: delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] On Behalf Of Marshland Engineering Sent: Thursday, 4 August 2011 7:47 p.m. To: delphi@delphi.org.nz Subject: Re: [DUG] HEX to decimal Been there done that edit2.text := IntToStr(StrToInt('$' + sRaw)); Result '[' is not a valid integer. ** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.clearswift.com ** ___ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe
Re: [DUG] HEX to decimal
The data returned in SerialPortNG.ReadNextClusterAsString, is it a buch of chars at a time, or just one at a time? If its a bunch of them at a time, you will need to do a conversion one char at at time in a loop. i.e. for x:=0 to length(sRaw) do begin ivalue:= ORD(sRaw[x])) ; end; something along those linesI didnt write that in Delphi, I just did it from memory but it should help a bitI hope. Jeremy On Fri, Aug 5, 2011 at 8:43 AM, Steven Knight steven.kni...@ecan.govt.nzwrote: You might need to use the ORD function byte by byte ** ** Steven ** ** *From:* delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] *On Behalf Of *Marshland Engineering *Sent:* Thursday, 4 August 2011 7:47 p.m. *To:* delphi@delphi.org.nz *Subject:* Re: [DUG] HEX to decimal ** ** Been there done that edit2.text := IntToStr(StrToInt('$' + sRaw)); Result '[' is not a valid integer. ** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender of the message. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.ecan.govt.nz ** ___ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe ___ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe
Re: [DUG] HEX to decimal
just noticed I missed a -1 in the for loop. Should be for x:=0 to length(sRaw) -1 do Jeremy On Fri, Aug 5, 2011 at 9:32 AM, Jeremy Coulter jscoul...@gmail.com wrote: The data returned in SerialPortNG.ReadNextClusterAsString, is it a buch of chars at a time, or just one at a time? If its a bunch of them at a time, you will need to do a conversion one char at at time in a loop. i.e. for x:=0 to length(sRaw) do begin ivalue:= ORD(sRaw[x])) ; end; something along those linesI didnt write that in Delphi, I just did it from memory but it should help a bitI hope. Jeremy On Fri, Aug 5, 2011 at 8:43 AM, Steven Knight steven.kni...@ecan.govt.nzwrote: You might need to use the ORD function byte by byte ** ** Steven ** ** *From:* delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] *On Behalf Of *Marshland Engineering *Sent:* Thursday, 4 August 2011 7:47 p.m. *To:* delphi@delphi.org.nz *Subject:* Re: [DUG] HEX to decimal ** ** Been there done that edit2.text := IntToStr(StrToInt('$' + sRaw)); Result '[' is not a valid integer. ** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender of the message. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.ecan.govt.nz ** ___ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe ___ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe
Re: [DUG] HEX to decimal
Adding more characters serial_send('B'); serial_send('C'); serial_send('D'); serial_send('E'); I get B(Tú 66 40 84 250 B(Tú 66 40 84 250 ___ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe
Re: [DUG] HEX to decimal
What version of Delphi are you using? Could the string be returned as a Unicode string? or is it an AnsiString?I'm using Ver 6 Apparently ORD works with 1 for the first character and not 0 just to be confusing !!! PS Using 0 returns a blank. ___ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe