Code for Send/Receive TTL/Comport Sample?


Closed Thread
Results 1 to 40 of 53

Hybrid View

  1. #1
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    Yes that is one of the things i wasnt sure of, in my other forum they sugest sending whatever is in the textbox as a string, see below

    Sub SendSerialData(ByVal data As String)
    ' Send strings to a serial port.
    Using com1 As IO.Ports.SerialPort = _
    My.Computer.Ports.OpenSerialPort("COM1")
    com1.WriteLine(data)
    End Using
    End Sub

    this as far as I know sends it character by character as ascii? am i right in this. if so I could take and convert the number to its ascii character and then send it, but that seems backwards. I would prefer to send it in binary or decimal but I prefer binary. easier to see whats going on. I may have to just send the pic some data and see what it does. but thats one of the reasons I wanted to get some of my questions answered before I get frustrated
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  2. #2
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    RS232 (serial) is purely a dumb pipe. You toss a byte in one end and it pops out the other. It does a number of things you can ignore, like add and remove start / stop bits, sometimes buffer a couple packets, and so on, but for your purposes you get out EXACTLY what you put in. So you decide what the bytes mean. You could send binary / hex / decimal numbers, or ascii, or morse code, or make up your own - as long as the receiver you build can read what the sender you build sends.

    If you use a commercial terminal program, it will send the ascii code for what you type. So if you type number "1" on the computer, what is sent is actually hex 31(decimal 49). The PIC gets hex 31. If you write a program in VB or any other language to send a hex 1 when somebody hits the "1" key (or any other key if you wish), then that is what the PIC will see. Nothing hard here. If you are coding both ends of the pipe, you have complete control.

    When you want to talk to other devices or systems, you need to know what the existing convention is. So if you think you will talk to commercial terminal programs, or certain serial displays, you are better off sending ascii. If you will be doing machine to machine stuff where you control both ends, do what pleases you. But you won't find anything automatically translating here. In most programming languages, text is stored as ascii, so if you are using a language that defines variables as text, or integer, etc. then you can convert numbers to ascii by converting to text. PBP does not distinguish between types of variables, other than by size. (At least not 2.6) but does have some things to make dealing with text easier. Read the manual - it will help.

    Clear as mud?
    Last edited by Charlie; - 29th June 2013 at 12:54.

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,705


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    Charlie is right txsta = $24 is affecting the baud rate and is just wrong

  4. #4
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Code for Send/Receive TTL/Comport Sample?

    every thing ive read including the melabs samples say to use $20 for baud rates lower than 9600 and $24 for higher, I even used a online calculator and pluggedin my info and it said that. so if thats wrong what would you suggest?

    Ive tried 24 and 20
    Last edited by wdmagic; - 2nd July 2013 at 16:07.
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

Similar Threads

  1. how to send and receive sms using vb?
    By shyhigh2002 in forum Off Topic
    Replies: 0
    Last Post: - 1st April 2009, 10:18
  2. please who can help me for sample code
    By jasem700 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd February 2009, 21:41
  3. How to build modem for only send and receive the msg
    By PoTeToJB in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 7th April 2006, 14:37
  4. send and receive data using pic 16f84a
    By PoTeToJB in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2006, 21:12
  5. send and receive data using pic 16f84a
    By PoTeToJB in forum Serial
    Replies: 1
    Last Post: - 25th February 2006, 15:47

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts