PDA

View Full Version : can't opening comm



hendryawan
29-03-2011, 06:29
Dear,
I can not openingg the comm port every time after startup the pc.:confused:
So I only running the other program like VB or hyperterminal with related comm opening, after that the thin basic program with communication can running normal. I already tried with 3 computers.
What is the problem with my program?
thank you verymuch
regard

hendryawan

ErosOlmi
29-03-2011, 07:06
It is quite hard to understand without looking at the source code of your program.
Have you tried adding something like

...
DIM MyErrorCode AS LONG
MyErrorCode = ERR
...

just after your COMM opening command and see what is MyErrorCode value?

hendryawan
04-04-2011, 06:05
Dear,
I has been add the error number, but the return number is always 0.
I attatch the program and print screen of my program result.
The screen no_respon is first time I running the program.
And the screen with_respon is after I open the other program with using comm1.

thankyou verymuch

regard

hendryawan

ErosOlmi
04-04-2011, 07:10
I think you need to first open COM port and just after that set communication parameters.

hendryawan
04-04-2011, 08:30
Thank Eros,
I already try, but the result is same with my previous program
regard

hendryawan

ErosOlmi
04-04-2011, 09:57
hendryawan,

the problem with such situation is that I cannot replicate your local device situation, so please be patient if I ask more and more or I try to suggest different path that does not bring into an immediate solution.

So here my next try:
are you sure you don't need to first send some kind of command to your device in order it to reply? Usually with serial devices you need first to send a command, than wait for response. For example some nextwork device that have a serial console (switch or routers) you usually neext to send an enter key in order to wake them up.

Eros

hendryawan
04-04-2011, 10:28
Dear Eros,
I just made the device microcontroller only sending "count = xxx" to PC.
My thin basic program is only read from my device, no cammand request to my device.
Maybe you can try with two PC to made communication, one pc use hyperterminal and the other one is use thin basic program.
thank

hendryawan

Michael Clease
04-04-2011, 10:45
Hello Hendry,

try this


'---Open the port
COMM_Open( "COM1", hcomm )
If Err <> 0 Then
PrintL "error: " + Err
Else
Do
If COMM_Get( hcomm, %COMM_RXQUE ) <> 0 Then ' Get size of incoming data
sBuffer = COMM_Line(hComm) 'waiting rx data with CRLF to continue
Console_WriteLine(sBuffer)
End If
Loop While Console_WaitKey = "" ' Anykey to quit

End If

'closing comm
Regards

Mike

hendryawan
06-04-2011, 02:17
Dear Mike and Eros,
I still can not solve my problem, please any idea?
regard

hendryawan

ErosOlmi
06-04-2011, 06:50
hendryawan

some questions for you, sorry

Just after COMM_FreeFile, what is the value of hComm file channel?
Can you please also print Err value after COMM_FreeFile?

You said that if you first run another application to open com port and than use thinBasic script, all is ok. This can be a symptom of missing parameter or a wring parameter. Can you please double check all COMM_Set options are what they need to be?

Is "COM1" the correct port on which your card is on?
Is there another application using "COM1" running at the same time?

When you use Hyperterm to test, does your card immediately send out text buffer after connection or you need to press some keys like <enter> to wake it up? If yes, try to add a COMM_Send(hComm, $CRLF) after COMM_Open and a sleep 200 to give some the time to the device.

Eros

hendryawan
06-04-2011, 16:54
Thankyou Eros,
I am sure that my communication port is COMM1.
About the ERR code seem no effect, the value always 0. I check with opening program in the same time with accesing comm1, the thin basic return ERR number still 0.
Would you like give me the sample of program?
The spec of program only read data (count = xxx + lfcr) that I send from my device, no need command request.
thank you verymuch

regard

hendryawan

Michael Clease
06-04-2011, 17:10
I think you need to open the port before setting the parameters

try this it will loop and print any data received until you press a key.



Uses "COMM"
Uses "CONSOLE"
Dim hcomm As Long
Dim sBuffer As String
Dim nBytes As Long
Dim errnumbr As Long

'---Get Comms file number and assign
hcomm = COMM_FreeFile

'---Open the port
COMM_Open( "COM1", hcomm )
If Err <> 0 Then
PrintL "Open Comms error: " + Err
Else
'---Set up all comms parameters
COMM_Set( hcomm, %COMM_BAUD, 4800 )
COMM_Set( hcomm, %COMM_BYTE, 8 )
COMM_Set( hcomm, %COMM_NULL, FALSE )
COMM_Set( hcomm, %COMM_PARITY, FALSE )
COMM_Set( hcomm, %COMM_PARITYTYPE, 0 )
COMM_Set( hcomm, %COMM_STOP, 0 )
COMM_Set( hcomm, %COMM_RXBUFFER, 64 )

Do
If COMM_Get( hcomm, %COMM_RXQUE ) <> 0 Then ' Get size of incoming data
NBytes = COMM_Get(hComm, %COMM_RXQUE)
COMM_Recv(hComm, NBytes, sBuffer)
Console_WriteLine(sBuffer)
End If
Loop While Console_WaitKey = "" ' Anykey to quit

End If

'closing comm
COMM_Close( hcomm )
Console_WriteLine("end testing")
Sleep (3000)

hendryawan
07-04-2011, 07:04
Thankyou Mike,
I has been test your script, but the result is only blank console windows.
I also check with my first action that running the other application with communication, the result is still same. I check with my first program working normaly.
regard

hendryawan

hendryawan
10-12-2012, 03:45
Dear all,
It's long time to followup my project.
Now I found ubnormality with thinbasic. Normaly I run the application using comm port. In thinbasic after I run the application (still can't work) then after I close the program, I try to use dos command mode com1
8075

The baudrate still in 1200 eventhought I set baudrate in thinbasic application is 4800. For the other application (not thinbasic) the baudrate in 'dos cmd mode com1' is same as I set in the application.
Please help me.
best regards

hendryawan

Michael Clease
10-12-2012, 13:18
I am not sure if I understand correctly but are you asking if the baudrate for com1 should stay at 4800 after you have closed the TB script? If that is your question I would expect it to return to the default setting for that com port not what you set in your program.

hendryawan
11-12-2012, 02:38
Thank for reply,
I just try the communication program with COM1 like hyperterminal or everything application with com. I has been try to change value of baudrate then open and close the program and check with command "mode com1" in dos, the result is the last value that I set. Not like in thinbasic eventhought I change the value of baudrate its no effect in mode com1 command.
Any suggestion?
Thank and best regards

Hendryawan