Results 1 to 9 of 9

Thread: [RESOLVED] RS232 Visual Studio 2005

Hybrid View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Resolved [RESOLVED] RS232 Visual Studio 2005

    How to send logic 1 to pin 3 in Visual Studio 2005. In Visual Basic 6.0 code is simpe: TXD 1, or TXD 0, but I don't know how to do this in Visual Basic 2005, that's important that is logic 1 on PIN 3 of RS232 (serial COM port). Thanks.

  2. #2
    New Member
    Join Date
    Dec 2009
    Posts
    5

    Re: RS232 Visual Studio 2005

    Hiyah

    I'm pretty sure that PIN3 is used only for receiving data, if you want to do this you'll have to make a custom RS232 cable, where you map PIN 2 to PIN 3.

    As for the code, I think you'll just have to send a boolean
    I'll try and come up with an example if you want... No promises though, I've only sent AT Commands to a modem haha

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: RS232 Visual Studio 2005

    Hi,

    Yeah. Please try to do same examples with this RS232 port. I just want to switch on and switch of one LED on serial port, but code must be write in Visual Studio 2005. Thanks!

  4. #4
    New Member
    Join Date
    Dec 2009
    Posts
    5

    Re: RS232 Visual Studio 2005

    Hey

    I'm hoping that this code will work for you:
    Code:
            Dim Port As New IO.Ports.SerialPort("COM1") ''Create the object
            Port.Open()
    
            Dim OStream As New IO.StreamWriter(Port.BaseStream) ''Output stream
            OStream.Write(True) ''Hopefully this will send a single bit...
    I'm hoping it will send a single bit to pin three, if it doesn't work, it might be worth checking the pin mapping for your device..

    I dont know if the code will work... But it's worth a try?


    Aaron

  5. #5
    Fanatic Member
    Join Date
    Sep 2009
    Location
    Lakewood, Colorado
    Posts
    621

    Re: RS232 Visual Studio 2005

    If you must use Pin3 (Tx Data), and not another pin, then you can control its state after opening the port, by using Break.

    Example,

    SerialPort.BreakState = True
    SerialPort.BreakState = False

    More natural, I think, might be to use the RTS output line (Pin 7).

    SerialPort.RTSEnable = True
    SerialPort.RTSEnable = False

    In either case, set the PortName property and call the Open method to enable this. Naturally, I'm talking about the SerialPort control that is in the Toolbox.

    Dick
    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: RS232 Visual Studio 2005

    I tried your code. It turns on LED and for 2-3 sec it turns off LED on serial port and give the error. Do you sure I can use RTS with your code?

    Just:

    SerialPort.RTSEnable = True 'for turn on
    SerialPort.RTSEnable = False 'for turn off

    I tried this code and when I run it and click button it give me error and exit the program.

    When I add "On Error Resume Next" the same thing happened.

    What to do??
    Last edited by hepeci; Dec 2nd, 2009 at 05:03 PM.

  7. #7
    Fanatic Member
    Join Date
    Sep 2009
    Location
    Lakewood, Colorado
    Posts
    621

    Re: RS232 Visual Studio 2005

    I have no idea what code you are using, you didn't post it. There should be no error, so your code has a problem.

    You cannot say, "I did this," and not say exactly what "this is." I would have to guess, and while I'm good at some things, guessing is not one of them.

    Dick
    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: RS232 Visual Studio 2005

    I have done it!

    In Form Load

    Port.Open

    Turning on: Port.DtrEnable = True AND Port.BreakState = True

    Turning off: Port.DtrEnable = False AND Port.BreakState = False

    Thanks all!

  9. #9
    Fanatic Member
    Join Date
    Sep 2009
    Location
    Lakewood, Colorado
    Posts
    621

    Re: RS232 Visual Studio 2005

    Good. Please mark the thread "Resolved."

    Dick
    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

Posting Permissions

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



Click Here to Expand Forum to Full Width