Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
4
Erster Beitrag:
vor 8 Jahren, 3 Monaten
Letzter Beitrag:
vor 8 Jahren, 3 Monaten
Beteiligte Autoren:
Andres Sanchez, christoph, Alexander Predl, Mitchell

Reading data on serial port

Startbeitrag von Mitchell am 06.06.2009 09:53

Dear Covers,
anyone can advise me please on how to read data on serial port ? I tried the help file "sOpen", sRead , etc.... but none of them is working

nPort = sOpen(1, 4096, 4096, sDefaultTimeout, True)
IF ErrorOccurred THEN
Error()
ELSE


// Configuring I/O
sParameter(nPort, 4800, 0, 8, 1, True, True, True)

// Insert your code here
xNumber is int


Info("press ENTER now")

sMessageRead is string

xNumber = sInEntryQueue(nPort)
sMessageRead = sRead(nPort, xNumber)
info(sMessageRead) // this line is giving empty string .


advise please.

thanks

Antworten:

Hi!

First of all i use a sysTimer or a sEvent. Your other code should work properly!

In my opinion (tested) do not use sEvent with ThreadExecute/ThreadWaitSignal/ThreadSendSignal in the same window... this is not working (at the moment)


//Code to use with TimerSys
Local
nPort is int

nPort=sOpen("COM1:", 5000, 5000, 5000)
sParameter(nPort, 9600,0,8,0, True , True , True)
TimerSys("SerialRead", 50, 1)

//Dont't forget to close the com port on closing window/procedure...
sClose(nPort)

Procedure SerialRead(PortNum,Event)
info(sRead(1,sInEntryQueue(1)))



//Code to use with sEvent
Local
nPort is int

nPort=sOpen("COM1:", 5000, 5000, 5000,true)
sParameter(nPort, 9600,0,8,0, True , True , True)
sEvent(nPort,sEveCharReceived,"SerialRead")

//Dont't forget to close the com port on closing window/procedure...
sClose(nPort)

Procedure SerialRead(PortNum,Event)
info(sRead(PortNum,sInEntryQueue(PortNum)))



von Alexander Predl - am 06.06.2009 12:37
Hello Mitchel,

nPort = sOpen(1,..) dont give you the real PortNumber. You cannot use nPort in sParameter,sread, sinentyqueue etc. You must give the real PortNumber - in your case, you has open COM1 in sOpen. sMessageRead = sRead(1, xNumber) give you what you want.

Christoph

von christoph - am 06.06.2009 12:43
Mitchell

// Configuring I/O
sParameter(nPort, 4800, 0, 8, 1, True, True, True)

I think that your problem is in the stop bits you have 1 that is equivalent to 1.5
and this is seldom used, if you need 1 stop bit, you must put 0 in the stop bits.

: Integer
Number of stop bits:
0 1 stop bit
1 1.5 stop bits
2 2 stop bits


I know cause I made the same mistake.

Hope it helps

Andres Sanchez


von Andres Sanchez - am 07.06.2009 02:55
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.