Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting QBasic CHR$(13)+CHR$(10) to C#

I'm trying to pass a straight ASCII text command through my serial port, something like this:

string cmd = "<ID00><PA>Hello World. ";
template.Serial.WriteLine(cmd);

Serial being a SerialPort property reference. I've also tried 'Write(cmd)' but even though the serial port is open the command never seems to go through. I've found that I'm supposed to add a Carriage return (cr) and a Line Feed (lf) to the end of the message, but I don't know how to do this in C# short of converting everything to bytes but It needs to be passed as ASCII Text from my understanding of the protocol.

I found someone's QBasic source that looks like this:

100 OPEN "COM1:9600,N,8,1,CS,DS,CD" AS 1
200 PRINT #1,"<ID00>";:REM SIGN ADDRESS, 00 FOR ALL
210 PRINT #1,"<PA>";:REM PAGE "A" (MESSAGE NUMBER, A-Z)
220 PRINT #1,"<FQ>";:REM OPTIONAL DISPLAY MODE, (FA-FZ), "APPEAR"
230 PRINT #1,"<CB>";:REM OPTIONAL COLOR CHANGE, (CA-CZ), "RED"
240 PRINT #1,"Hello World";:REM TEXT
250 PRINT #1, CHR$(13)+CHR$(10);:REM MUST END IN CARRIAGE RETURN/LINE FEED

So how would you convert CHR$(13)+CHR$(10) to characters that you append to the end of a string line in c# code to be sent through a serial port?

like image 667
roadmaster Avatar asked Mar 19 '14 15:03

roadmaster


People also ask

What does Chr 13 mean in VBA?

Chr(10) is the Line Feed character and Chr(13) is the Carriage Return character.

What is CHR 13?

What is Chr(13) The ASCII character code 13 is called a Carriage Return or CR . On windows based computers files are typically delimited with a Carriage Return Line Feed or CRLF . So that is a Chr(13) followed by a Chr(10) that compose a proper CRLF .

What is CHR 34 in VB net?

Use Chr(34) to embed quotation marks inside a string, as shown in the following example: sSQL = "SELECT * FROM myTable _ where myColumn = " & Chr(34) & sValue & Chr(34)


1 Answers

In literal terms, CHR$(13)+CHR$(10) is ((char)13) + ((char)10), although for legibility, it would be better to use the string "\r\n"

like image 159
l33tmike Avatar answered Sep 22 '22 07:09

l33tmike