Results 1 to 24 of 24

Thread: RS232 Problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Unhappy RS232 Problem

    I'm using interface with relay and interface is connected to computer on COM (serial) 9 pins port. In Visual Studio 2005 I'm using this code:

    Code:
    SerialPort1.Open
    SerialPort1.DtrEnable = True
    SerialPort1.Breakstate = True
    This is code for turning on interface, and that's OK, BUT when I turn off my computer and restart it interface is turn on and turn off a few times, and when computer stop loading Windows XP everything is OK. Please, help me. Thanks!

  2. #2
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: RS232 Problem

    Be sure to add:

    SerialPort1.Close

    To the Form_Closing() event.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: RS232 Problem

    Are you sure that's reason?

    I don't close port...

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: RS232 Problem

    What do you mean when you say "BUT when I turn off my computer and restart it interface is turn on and turn off a few times..."?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: RS232 Problem

    I'm from Croatia, and English isn't my mother language, so sorry if you have some problems with understanding me.

    I wanted to say that I didn't use
    Code:
    SerialPort1.Close
    , and I ask you, are you sure if I write
    Code:
    SerialPort1.Close
    that everything will be OK.

    Means that I don't know why my LED turns on and turns off and when loading XP is finish everything is OK, i can run my program and turn on and turn of LED with buttons.

    I hope you understand me now.

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: RS232 Problem

    The driver for the Serial port is probably initializing it which will turn certain pins (DTR) on / off when the PC is re-booted.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: RS232 Problem

    Yes, but how to solve this?

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

    Re: RS232 Problem

    That is the way that it works for DTR, and this is beyond control from the application level. However, you can use RTS instead of DTR. I do not think that it toggles during startup. Using Tx Break this way is not really a supported mode, so the actual state may be indeterminate.

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

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: RS232 Problem

    I tried with RTS and the same thing happened.

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

    Re: RS232 Problem

    Let me add to what I said in my last message. The serial port is designed for serial data transfer, not for controlling LEDs or other hardware. Thus, when you use it for something for which it isn't designed, you have to live with the limitations.

    There are other solutions, but these may require more hardware.
    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: RS232 Problem

    Yes, I know. Maybe it can be done with PIC16F84, so on computer SerialPort1.Write, and in PICBASIC SERIN, but I'm interested in exactly what to do.

  12. #12
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: RS232 Problem

    Oh, I understand what he's doing now. He's using the serial port to power a device; i.e. use it as a switch? No, you can't use the serial port if you want consistency. When the computer starts up, the serial port outputs may be in an indeterminate state (though there are some electronics tricks you can do to bias it to one state or another).

    What you need is a simple Digital I/O device you can program like this one. Also, if your computer still has one, you can use a parallel port, which is more stable for this kind of stuff to control it.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  13. #13
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: RS232 Problem

    hep - what are you trying to do? showing code doesn't give much clue. i agree that the state of any of the pins on the serial port might be in an indeterminate state and if it is crucial that that not be true then other hardware will be needed.

    you might also try setting DTR and RTS high to indicate whatever it is.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: RS232 Problem

    Is there any solution to do this with PIC microchip? In PICBasic command is SERIN, and in Visual Studio 2005 is
    Code:
    SerialPort1.Write...
    So, if someone exactly know what to do, tell me.

  15. #15
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: RS232 Problem

    Let me ask again, what are you trying to do?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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

    Re: RS232 Problem

    If your PC has a built-in (hardware) printer port, you can download IONet.dll from my homepage. This will allow you to control the output pins from your program, and they will not change state when the PC or your program starts up.

    For even more flexibility, you might want to look at: www.activewire.com and www.phidgets.com -- there are others, too.

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

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: RS232 Problem

    @DickGrier, that's it what I am looking for, but for Serial Port.

  18. #18
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: RS232 Problem

    Quote Originally Posted by dbasnett View Post
    Let me ask again, what are you trying to do?
    one last time...
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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

    Re: RS232 Problem

    If you go to my PC Data Acquisition pages (www.hardandsoftware.net), you will see how I did this with my own design. I used a Bluetooth serial adapter, so that is was wireless, but you could simply replace the BT adapter with a serial cable.

    For a commercial product set, you might look at: www.controlanything.com.
    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: RS232 Problem

    @dbasnett, I described three times, but one more time!

    I have interface with LED and relay. I want to turn on and turn off relay and LED with Visual Studio 2005.

    I'm using following code:

    This is for turning on:

    Code:
    SerialPort1.Open
    SerialPort1.DtrEnable = True
    SerialPort1.BreakState = True
    This is for turning off:

    Code:
    SerialPort1.Open
    SerialPort1.DtrEnable = False
    SerialPort1.BreakState = False
    And everything is OK, while I don't turn off my computer. When I turn on my computer (restart it actually), when Windows XP start loading and then LED started blink (fast turn on and turn off), so I want to modify hardware or software (on computer) because I want to avoid toggle on COM (serial port) while starting operation system.

    The same thing is when I'm using RTS.

    Code:
    SerialPort1.Open
    SerialPort1.RtsEnable = False
    SerialPort1.BreakState = False
    So, if you don't understand now, I really don't know what's the problem.

  21. #21
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: RS232 Problem

    I am a little surprised that RTS changes states when you reboot. The documentation for the 16550 seems to indicate that the chip drives RTS (and other pins) to their inactive state. I didn't read the entire spec sheet, so maybe I missed something, or maybe the driver is doing something strange.

    http://www.national.com/ds/PC/PC16550D.pdf

    One other thought, have you checked the cable you are using?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: RS232 Problem

    Cable is OK. Is there some posibility to deal with this problem? With PIC16F84, for example?

  23. #23
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: RS232 Problem

    If you have a device at the end of the RS232 cable then you could make the control more than simple RS232 control signals.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: RS232 Problem

    Actually, now I don't uderstand what do you mean. =D What's interface?

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