rs232 communication with microcontroller

New to FreeBASIC? Post your questions here.
stacker
Posts: 4
Joined: Jul 15, 2018 13:28

rs232 communication with microcontroller

Postby stacker » Jul 15, 2018 14:28

Hi all,
i'm new to FB, i need to create an application that send command to pic16f877 (micro).
ex; Pc send "ADCxxx" where "xxx" is delimiter, pc wait (with timeout) the reponse from micro. Micro send binary value 16bit (first byte have six 0 msb and 2 lsb, second byte all 8 bit..... is 10bit ADC).

i try with autoit (i'm not newbie but serial communication is hard for me in script language)...

In short, Pc send command (ADCxxx ONxxx OFFxxx) and micro always send response (OK or value "16 bit"). I need also to display value in a label or textbox and have button to start cycle.

Anyone can help me ?
Can you suggest a GUI tool ?

thanks
grindstone
Posts: 547
Joined: May 05, 2015 5:35
Location: Germany

Re: rs232 communication with microcontroller

Postby grindstone » Jul 15, 2018 22:40

Hello stacker and welcome to the forum!

The serial port is accessed by OPEN COM.

If the µC provides a regular dataflow, you can communicate with it via the PRINT # and INPUT # statements.
Last edited by grindstone on Jul 15, 2018 22:45, edited 1 time in total.
stacker
Posts: 4
Joined: Jul 15, 2018 13:28

Re: rs232 communication with microcontroller

Postby stacker » Jul 15, 2018 22:44

Hi grindstone can you explain with example?
uC dataflow is only when pc send command... pc wait for return message from uC.


Thanks
grindstone
Posts: 547
Joined: May 05, 2015 5:35
Location: Germany

Re: rs232 communication with microcontroller

Postby grindstone » Jul 15, 2018 22:55

In a trice: This snippet tests the port if connected to a loopback plug:

Code: Select all

ScreenRes 300,300,32

'Open Com "com4: 9600, N, 8, 1,cs0,ds0,cd0,rs" As #1
Open "c:\test.txt" For Binary As #1

Dim As String Puffer, Taste
 
Do
    Taste = InKey
    If (Taste <> "") Then
        Put #1, , Taste
    End If
   
    If Loc(1) > 0 Then
        Puffer = Space(Loc(1))
        Get #1, 1, Puffer
        Seek 1,1 'simulated reading of the receive buffer
        Print Puffer;
    End If
    Sleep 100
Loop Until Taste = Chr(27)

Close #1
Kill("c:\test.txt")

If everything's OK, your keystrokes should be printed on the screen.
stacker
Posts: 4
Joined: Jul 15, 2018 13:28

Re: rs232 communication with microcontroller

Postby stacker » Jul 16, 2018 4:56

Thanks i will try today.
But i think i need more help with fb :( :(
grindstone
Posts: 547
Joined: May 05, 2015 5:35
Location: Germany

Re: rs232 communication with microcontroller

Postby grindstone » Jul 16, 2018 9:13

stacker wrote:But i think i need more help with fb :( :(
You're always welcome :-)
stacker
Posts: 4
Joined: Jul 15, 2018 13:28

Re: rs232 communication with microcontroller

Postby stacker » Jul 25, 2018 7:17

Hi, for now i find solution in Autoit. I think to "convert" in fb in the future.
Thanks for support

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 5 guests