|
-
Dec 17th, 2009, 07:42 AM
#1
Thread Starter
Addicted Member
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!
-
Dec 17th, 2009, 08:28 AM
#2
Re: RS232 Problem
Be sure to add:
SerialPort1.Close
To the Form_Closing() event.
-
Dec 17th, 2009, 08:29 AM
#3
Thread Starter
Addicted Member
Re: RS232 Problem
Are you sure that's reason?
I don't close port...
-
Dec 17th, 2009, 08:59 AM
#4
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..."?
-
Dec 17th, 2009, 09:03 AM
#5
Thread Starter
Addicted Member
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 , and I ask you, are you sure if I write 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.
-
Dec 17th, 2009, 09:21 AM
#6
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.
-
Dec 17th, 2009, 12:43 PM
#7
Thread Starter
Addicted Member
Re: RS232 Problem
Yes, but how to solve this?
-
Dec 17th, 2009, 01:00 PM
#8
Fanatic Member
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)
-
Dec 17th, 2009, 01:01 PM
#9
Thread Starter
Addicted Member
Re: RS232 Problem
I tried with RTS and the same thing happened.
-
Dec 17th, 2009, 01:02 PM
#10
Fanatic Member
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)
-
Dec 17th, 2009, 01:04 PM
#11
Thread Starter
Addicted Member
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.
-
Dec 17th, 2009, 01:32 PM
#12
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.
-
Dec 17th, 2009, 01:53 PM
#13
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.
-
Dec 17th, 2009, 02:00 PM
#14
Thread Starter
Addicted Member
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.
-
Dec 17th, 2009, 02:00 PM
#15
Re: RS232 Problem
Let me ask again, what are you trying to do?
-
Dec 17th, 2009, 02:03 PM
#16
Fanatic Member
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)
-
Dec 17th, 2009, 02:08 PM
#17
Thread Starter
Addicted Member
Re: RS232 Problem
@DickGrier, that's it what I am looking for, but for Serial Port.
-
Dec 17th, 2009, 02:09 PM
#18
Re: RS232 Problem
 Originally Posted by dbasnett
Let me ask again, what are you trying to do?
one last time...
-
Dec 17th, 2009, 02:20 PM
#19
Fanatic Member
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)
-
Dec 17th, 2009, 02:23 PM
#20
Thread Starter
Addicted Member
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.
-
Dec 17th, 2009, 03:09 PM
#21
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?
-
Dec 18th, 2009, 07:31 AM
#22
Thread Starter
Addicted Member
Re: RS232 Problem
Cable is OK. Is there some posibility to deal with this problem? With PIC16F84, for example?
-
Dec 18th, 2009, 09:12 AM
#23
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.
-
Dec 18th, 2009, 12:11 PM
#24
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|