Solved

Serial Port in Windows XP

Posted on 2002-07-18
79
1,877 Views
Last Modified: 2013-11-15
I have an application that writes to a serial port device using the CreateFile and WriteFile functions. The device simply takes the pulse from the serial cable and when it recieves a pulse it takes some electricity from the power source. It then simply lights a LED. So when it's recieving data the LED is on. When it's not, the LED is off. The LED is just a test before the real functionality is implemented. My software works successfully on Windows 95, 98, Me, and 2K, but not Windows XP. I tried removing my device and replacing it with an old serial modem. When I started sending data the modem lights lit up. I know that data is being transmitted. The only difference was that I was using a modem instead of the device and I was using the modem serial cable (the cable for my project is attached to the device so I can't use it for the modem). Can XP be incompatible with my device? I've noticed several posts on message boards and I think there is someone in the EE hardware group who may be having a similar problem, but i'm not sure. I have found no answers. MSDN reports nothing about this.
0
Comment
Question by:axia
  • 41
  • 15
  • 11
  • +5
79 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
Comment Utility
It is possible that WinXP includes some radical changes to the Serial port I/O handling, but it is unlikely -- Imagine how many programs would break and think of the tech support nightmare.  

If your XP test machine is malfunctioning, it is more likely to involve a problem with a third-party driver that is installed or some special hardware.  Turn your attention to these questions:

1) What hardware is different between the computers that work and the one that does not?  The only way to actually point the finger at the OS would be to install WinXP onto, say, one of the Win98 computers that you have tried (same hardware) and see if the same test program fails in that situation.

2) Have you eliminated the possibility that there is other software in a layer between your program and the serial port?  Examples of such software is fax drivers, RAS dialup answering software, thired party device drivers, software that handles voice processing.  Also with certain low-cost internal modem/COM ports (WinModems), features of the hardware are actually simulated in software.

3) Have you eliminated the chance that it is related to default port settings?  This is the kind of thing that I would expect to be different between say Win98 and WinXP --default port speed, default flow-control, etc.
=-=-=-=-=-=-

If none of these can be isolated as the solution, we will need to know more about the problems.  Specifically:

A) In what way does the program/hardware fail?
B) Show the relevant code

-- Dan
0
 

Author Comment

by:axia
Comment Utility
I've tried it on 2 XP machines. One has Win2K and Win98 also installed on the same machine, and the program works fine on that machine for the other 2 operating systems. I can't imagine that WinXP is that different so I am curious as to why this program is broken when run on XP. I've had a friend try the program on 3 more XP computers and it fails on them too.

A) In what way does the program/hardware fail?
The device does not register that is is recieving any input (LED stays off).

B) Show the relevant code
I have tried about 5 different varients. This included just directly using CreateFile and WriteFile to using several libraries and some code that havman56 posted to another thread. I can show you one or more of the code examples, but I don't think that will help because if all 5 ways I tried (all of them were really just using Create and Write File, but the wrappers were organized a bit different) failed, but worked on a modem, I get the impression that the code must be working. Could this be an OS issue?
0
 
LVL 22

Expert Comment

by:ambience
Comment Utility
Are you sure WriteFile and CreateFile are not failing  ? checked the return codes ? GetLastError ?
0
 

Author Comment

by:axia
Comment Utility
nope. they succeed. the strangest thing is that it works on 2K but not XP.
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Good, I'm glad you are able to elimninate hardware issues.  It certainly sound like what you fear: an oddball difference between WinXP and other variants.

A search on Google groups yeilds an amazing number of people with similar problems (A apologize for not doing this first).  One person claimed that this sequence fixed the problem:

OpenCommPort = CreateFile(Commport, GENERIC_WRITE Or GENERIC_READ,
0, ByVal CLng(0), OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, 0)

See:  
     http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=5e3e4b5c26ea60f6&rnum=4

I searched for
   WinXP and Serial Port

and *many* programmers report problems.  Some say it is a security-related issue but I'm not so sure.  If that write-through thinby doesn't work, I'll continue looking.

-- Dan
0
 

Author Comment

by:axia
Comment Utility
ok thanks for your help. I won't have access to the code for another few hours. I need some sleep (it's been aout 30 hours so I should catch up on it :). I'll check that in the morning when I can actually give you an intelligent answer.

I'm "glad" to know that other people are sharing my pain.
0
 

Author Comment

by:axia
Comment Utility
umm, I don't know VB. I assume that things like "Or" means "|". I always found the syntax to be too "readable". It reminds me of English. What would I use for C++?
0
 

Author Comment

by:axia
Comment Utility
I will try this solution as soon as I get it in C++ but the guys says that his "incorrect" way didn't work in Win2K either. Mine does work in 2K. I don't think i was making the same mistake.
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
To make it in C++:
Use the code that you currently using, but use FILE_FLAG_WRITE_THROUGH as the second to last parameter in the call or CreateFile.

Just for kix, send the code that you are currently using to open the file.

-- Dan
0
 

Author Comment

by:axia
Comment Utility
Here's my code:
Comm = CreateFile(Port, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);

When I change to FILE_FLAG_WRITE_THROUGH it doesn't make a difference.
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
What is the value of Port?
What is the return value from the CreateFile Call?
Show the code that you use to write to the port.
What data are you writing?

Have you tried to use HyperTerminal or some other generic datacom application) in WinXP?

Have you tried looking at the default port settings on the WinXP computer (in the control panel).  Change various defaults and then try your code.

Try removing any modems that are installed in the Modess control panel

Try to disable then enable the comm port in Windows Device Manager.

See if you can access the port in DOS:
  copy con com1:
  keys keys <enter> <ctrl+Z>

Try booting up XP *without having the device plugged in to the serial port* then plug it in and try your program.  XP might think your device is a serial mouse.

-- Dan
0
 

Author Comment

by:axia
Comment Utility
> What is the value of Port?
"\\\\.\\COM1"

> What is the return value from the CreateFile Call?
It returns a HANDLE to the port that I use to write.

> Show the code that you use to write to the port.
WriteFile(Comm, "mytext", Count, 0, NULL); // Count=lenght of data

> What data are you writing?
For my test string I just use "abcdefghijklmnopqrstuvwxyz". All the device cares about is if it is recieving data or not. I can put what ever i want for data. There are no commands to send.

> Have you tried to use HyperTerminal or some other generic datacom application) in WinXP?
Yes. I have tried various apps including one written in VB and none of them work with the device. For my test I've been setting the baud really low (like 100) because i want my string to take a long time to be fully transmitted so the LED stays lit longer. I don't know how to set that in HyperTerminal but I've tested various similar apps and they didn't work.

> Have you tried looking at the default port settings on
> the WinXP computer (in the control panel).  Change
> various defaults and then try your code.
It's been tested on 5 XP computers and it didn't work on any of them. I don't think it's a problem with my specific computer. This app will be distributed and i can't tolerate users having to go in to the control panel to change values. I set all of that in my program anyway.

> Try removing any modems that are installed in the Modess control panel
See above answer.

> Try to disable then enable the comm port in Windows Device Manager.
No luck.

> See if you can access the port in DOS:
>  copy con com1:
>  keys keys <enter> <ctrl+Z>
That works on other devices but not on my device.

> Try booting up XP *without having the device plugged in
> to the serial port* then plug it in and try your
> program.  XP might think your device is a serial mouse.
I have been doing this the whole time.

*********************************************************************

The thing that bugs me is the fact that it works on every Windows but XP. I'm in a very interesting situation.

*It works on all other windows versions so the hardware device can't be an issue.
*In XP my software will communicate with other devices so it must be a problem with the hardware device.

To add to my frustration:
I have an app written in VB that works with the device on XP just fine. The guy who wrote it lost the code to it. This means that the device can be made to work with XP.

I know this is a really long shot but: Would it be possible to decompile the VB application and somehow see what was done and make it work in C++? I have no clue what version of VB it was done in but it's an exe file. I know this is a silly problem, but I've been working on this for weeks, pulling my hair, looking at every resource i could, until i finally broke down and posted it to EE.

Any ideas? I'll add more points if we can solve this soon. I only have 375 points left, but I'll throw in most of them.
0
 

Author Comment

by:axia
Comment Utility
********NOTE********
>> See if you can access the port in DOS:
>>  copy con com1:
>>  keys keys <enter> <ctrl+Z>
> That works on other devices but not on my device.

It might actually work but I can't see the LED light. it might be because at the baud i would have to type a whole bunch of characters. Is there a short command to send a lot of data fast? Like a loop, that I could use as a test?
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
>> is there a short command...
copy <filename> com1:

>> "\\\\.\\COM1"
Try opening the file as "COM1:" or "COM1"

>> It returns a HANDLE to the port that I use to write.
that's strange... :) just a sanity check: is it's value 0 or 0xffffffff?

Hmmm the VB program works... I wonder if it is using the Microsoft Communications Control (MSCOMM.OCX)... You might be able to tell by examining its dependencies.  Or you can whip out a quick dialog-based app to see if using the that AcxtiveX control magically works.

>>For my test I've been setting the baud really low (like 100)
That implies that you are calling SetCommState to set the DCB.  Perhaps the error is there... I know that some device drivers (especially those associated with WinModems) do not honor all DCB settings (I think the idea was that if the user can access the Internet, they could put the code to bed).

-- Dan
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
BTW with the command-prompt test, you can set the port speed etc by using the MODE command first.  Type
   MODE /?
to see the correct syntax.

-- Dan
0
 

Author Comment

by:axia
Comment Utility
> copy <filename> com1:
ok, i tested it using mode too and found that using the copy command gives the same results as my program. nothing gets to the device.

> Try opening the file as "COM1:" or "COM1"
Still doesn't work.

> that's strange... :) just a sanity check: is it's value 0 or 0xffffffff?
It is 0xffffffff.

> Hmmm the VB program works... I wonder if it is using the
> Microsoft Communications Control (MSCOMM.OCX)... You
> might be able to tell by examining its dependencies.  Or
> you can whip out a quick dialog-based app to see if
> using the that AcxtiveX control magically works.
I'm testing this now. I'll let you know soon.

> That implies that you are calling SetCommState to set
> the DCB.  Perhaps the error is there... I know that some
> device drivers (especially those associated with
> WinModems) do not honor all DCB settings (I think the
> idea was that if the user can access the Internet, they
> could put the code to bed).
I am using SetCommState, but why would I be going through a Winmodem driver? I think the only driver I'd be going through is the serial port driver which I'm sure would support pretty much any baud rate. If not, is there a specific low rate that would be universally supported?
0
 

Author Comment

by:axia
Comment Utility
I never really use ActiveX. I added the MSCOMM32.OCX control to my dialog. The properties for the control are set the way I want them. How do I send data?
0
 

Author Comment

by:axia
Comment Utility
Any more ideas?
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
If the handle is 0xffffff then it means that the CreateFile failed.  That is the root of your problem (I'm glad I persisted with the question!).  

Fix that and everything will work.  I don't know why it failed, but you should call GetLastError to learn the reason.

I'll be away for 10 days... so I can't follow up, but now that you know the main problem, I'm sure other experts can help.

-- Dan
0
 

Author Comment

by:axia
Comment Utility
rrr, I feel stupid. I made a really dumb debug mistake. It actually equals 0x000007c4.
0
 

Author Comment

by:axia
Comment Utility
FormatMessage/GetLastError gives: "The operation completed successfully."
0
 
LVL 4

Expert Comment

by:havman56
Comment Utility
axia

first open the hyperterminal on com1 or com2 port see whether u can get conected?
otherwise any other driver for ex u would ahve installed IRDA driver which uses one port( may be com1 ) which u may also accessing the same port?

so u will get errors .

0
 

Author Comment

by:axia
Comment Utility
> otherwise any other driver for ex u would ahve installed IRDA driver which uses one port
Not really sure what this means. I have no IRdA port. This has been tested on multiple XP computers and it works on none of them. HyperTerminal connects fine. CreateFile returns successfully. WriteFile returns successfully. The problem is that nothing is actually getting to the device itself.

As I said earlier:
*my program works on Win2K but not WinXP
*on XP my program communicates with devices like a modem successfully but not my device
*this has been tested on multiple computers
*a VB program which i don't have source code access to works with this device in XP
0
 
LVL 4

Expert Comment

by:havman56
Comment Utility
i feel u should know the format in which ur device recives data may be parity, baudrate ,start stop bits etc.

see with my exp i am saying in win 2k even u set stop bits as 1 . if u have UART of 2 stop bits  . even though mismatch it works fine .

so first see what the device is doing for getting the data .

see from ur statemnt XP comunicate with modem .
so program on XP is working fine .

u have to see the device side UART programming .
if u dont have acees to teh code of UART on device id try with trial and error method.

as far i consider there is no problem in XP program on PC .
but tehre may be mismatch with UART .
0
 

Expert Comment

by:Sabnis
Comment Utility
try this utiliy called Portmon
it works on XP
see if your program can send data on the port or not
0
 

Expert Comment

by:johanhz
Comment Utility
Axia,

Did you try accessing your hardware with Hyperterminal in another OS than XP ? Does This Work ?

Do you have any means by showing us your hardware (how the LED's are connected?)

I have just made a simple cable & LED connection (TXD connected to the anode, kathode fixed to ground with a series resistor), and tested with hyperterminal. The Led lights up! (and yes, OS = XP)

JOHan.
0
 

Author Comment

by:axia
Comment Utility
To follow up on all three posts:
*My program can write to the port. Other devices receive the data. Just mine doesn't.
*I can access the hardware with HyperTerminal or any other program under other operating systems.
*I did not design the hardware. I can tell you that it is much more complicated than the simple LED connection that you constructed. The LED is just a temporary indicator. It will be replaced later by a more sophisticated gauge. The wiring for this is more complicated.
*havman56: Since I didn’t design the device I don’t know how it is wired or what settings to use. I have been using the normal defaults. Are you suggesting that I connect to it in HyperTerminal trying different settings until one works? So you are saying that I may be sending data to the device improperly but Win9x/Win2K don’t mind, however XP handles things differently and complains?
0
 

Author Comment

by:axia
Comment Utility
I just tried about every combination of logical HyperTerminal settings I could think of and none worked.
0
 

Author Comment

by:axia
Comment Utility
anybody?
0
 

Expert Comment

by:johanhz
Comment Utility
Axia,

Did you try the suggestion of Sabnis? It helped me allot to solve serial issues.
You can find the utility Portmon on
http://www.sysinternals.com/ntw2k/utilities.shtml
This utility logs virtually everything that happens on the chosen comport. (all IOCTLS, etc)
compare the log of Win2000 & XP
0
 

Author Comment

by:axia
Comment Utility
I just tried that program. Every write is logged and in the result column "SUCCESS" is listed.
0
 

Expert Comment

by:johanhz
Comment Utility
Did you do the same thing on Win2000?
you can save the logfile.
what happens if you do a filecompare between the logfiles of 2000 & XP?
0
 

Author Comment

by:axia
Comment Utility
I can't directly compare the output because my program decides what to send at runtime based on realtime events. I also don't have access to my 2K machine right now, but I did it on my 98 machine and the log file was quite different. I assume it's the big difference between 9x and NT. Tomorrow morning I will post the log files from both 2K and XP. (I might change my program to write set data so the log files are directly comparable)
0
 

Author Comment

by:axia
Comment Utility
I just compared the log files. They are identical.
0
 

Author Comment

by:axia
Comment Utility
this would make me believe that i am doing everything correct. What could be the problem?
0
 

Author Comment

by:axia
Comment Utility
would someone please comment? The log files are the same. where is the error?
0
 

Expert Comment

by:johanhz
Comment Utility
Axia,

Sorry, Day off.
Could you please post the code where you do the baudrate setting stuff, handshaking, etc.

JOHan.
0
 

Author Comment

by:axia
Comment Utility
i will, but do you think that has somthing to do with it? If i hot swap the device for a modem while the program is running the modem gets that data, but the device doesn't. are there certain settings that may change based on which device is being programmed?
0
 

Expert Comment

by:johanhz
Comment Utility
Since I, and you don't know how the LED stuff is connected to the serial port, perhaps it is a combination of RTS, CTS, DTR etc that runs the LED

Again, It would be very helpful if you just could give the schematics of the cable & hardware you have.

I don't believe in devices that are incompatible with the serial port, except if they are not made to the serial specifications.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:axia
Comment Utility
like I said, i didn't design the device. It's made for a much moer complicated device. the led is just a test to verify evrything is working. it's on a PCB with what seems to be 20-30 connections all over the place. I'm trying to get as much info on it as i can as we speak. i'll post more code in the morning.
0
 

Author Comment

by:axia
Comment Utility
Ok. here's the deal. I have tried to communicate with this device in every way I can think of. I have used simple programs that don't set a baud rate, they just send data. those don't work either. i've tried using copy [filenamehere] com1 along with the mode command. none of this works. the device doesn't get input. like i said earlier, it's a dumb device. it has no microchip in it. it just checks for input. there is no reading involved. and when data is written the only way to see if it worked is to see if the functions return successfully and the indicator turns on. I think that I would be going in the wrong direction if i were to look at the code. From what i understand 2000 and XP are pretty much the same system. It works on 2K perfectly but not on XP. it seems to work on xp, all of the functions return successfully. when i swap in another device it gets that ouput.

would i be correct in assuming that what i should be focusing on is the differences between 2K and XP? I've used every combo of data and stop bits i can think of. i guess that doesn't even matter that much for this device. it's either on or off. are there any known differences between 2k and xp with respect to serial I/O?
0
 
LVL 4

Expert Comment

by:havman56
Comment Utility
yes i feel there may be serial driver issue . in XP .

1. if u tried ur best i feel there may be issue as i said . when i worked on 2000 even if i set 1 stop bit in hyper terminal and 2 stop bits in UART it is communicating properly .

2000 may not identify but where as xp may be identified and could not communicate.

2. see the device whether recives  in polled  mode or interrupt mode.
(assumtion)  if device works on polled or interrupt mode then XP may not support that mode.

have a buffer send it from a device to 2000 . log it!!
then same buffer send it to XP . log it!!!

if u get a data may be 00 00 or junk in XP 90% it is baudrate mis match .

if u dont get anything  taht is diifernt issue.
0
 
LVL 4

Expert Comment

by:havman56
Comment Utility
Axia

if u were struggling to solve a problem and wished to have a chat and to understand ur problem clearly i hope lets have a group chat in yahoo and analyse and we may get some results.

my yahoo id is micro_mangal@yahoo.com

johanhz and sabnis,
why cant u also join?

( i am trying my best to find a solution for u !!)

0
 

Author Comment

by:axia
Comment Utility
ok, i appreciate the trouble  you are going through tho help me. It would be great if we could have a live chat. let me just ask a few questions.

> have a buffer send it from a device to 2000 . log it!!
> then same buffer send it to XP . log it!!!
> if u get a data may be 00 00 or junk in XP 90% it is
> baudrate mis match .
> if u dont get anything  taht is diifernt issue.
What do you mean by this? The device cannot send data. I can not call ReadFile on this device. It only accepts data, it doesn't generate any. To the best of my knowledge the device simply checks if there is a current on the serial line, if it is present then the device turns on. if nothing is there it is off. i think it's pretty simple (i can't be sure though so i don't want to mislead anyone)

A live chat would be really great. I only have a few days to get this working or i could be fired (long long story). i tried to explain that the problem is most likely in the device but because it works with some old VB program the designers think it must be somthing with my software (and it could be :-() I will pay many more points if we can set up a chat soon, and even more points if i can get this solved within the next 48 hours.

Thank you so much!
0
 
LVL 4

Expert Comment

by:havman56
Comment Utility
tomorrow july 27  at 10:00 am ( morning) (IST)
IST=GMT+5.30 hrs

i will surely try my best to solve ur problem..
0
 

Expert Comment

by:johanhz
Comment Utility
All,

I am sorry for not responding, but this is my last day at work and I have to fix a lot of things before I leave.

I really really think you should focus on "How is the LED connected to the serial port, i.e. when does It go on or off". I know that in the future the LED will be replaced by a complex device, but the LED is the problem right now.

Since there is no microcontroller involved, it shouldn't be that difficult to reverse engineer the connection to the LED(s)

Axia, I won't be able to help you further but I do hope your problem get's solved.

Please inform me if you have found the solution. My email address is johanhz@sycron-it.com.

Good Luck!
0
 

Author Comment

by:axia
Comment Utility
umm, i'm at a complete loss as to what time that would be. I'm at GMT -8 hrs. I would that be 9:30PM on the 26th my time? If so that would mean it's in about 18 hours and 40 minutes? if so that would be fine! thanks for your help. it's probably like 3:20PM there but here's it's 2:50AM (i think) so i need some sleep. just asking a few questions, hoping the answers will be there when i wake up: how aer we having this chat? is it like an instant messanger or a website or what? I'll make an account for just about anything as long as it's free.
0
 

Author Comment

by:axia
Comment Utility
johanhz: thanks for the support. i'm doing my best to trace the connections on the PCB but it's enclosed in plastic and I will be killed if I break it trying to get a better look. the whole system that has been set for me to work with this device has been asinine. the hardware people have no idea how to program software and don't ever think of prodiving the developer with info about the hardware. oh well. I will do my best. at worst i loose a couple hundered dollars. in this case fighting is just not worth it, but solving the problem just might be :-)
0
 
LVL 4

Expert Comment

by:havman56
Comment Utility
ok axia

so by tomorrow at 10:00 am (IST) in morning ( GMT+5)indian timing .

i will be tehre may be u r in america so 12 hrs lapse.
we will chat in yahoo messanger . my id is micro_mangal@yahoo.com

we will try and anlyse in solving .

but i feel before coming just knwo differnt between XP and 2000 in serial communication.




 
0
 
LVL 4

Expert Comment

by:havman56
Comment Utility
Axia
any luck or improvement?

i am also seeing it!!
0
 

Author Comment

by:axia
Comment Utility
not as of yet. I am trying to get more details from the designers. at least i'm off the hook. I convinced the people that it wasn't my fault. i have another week to get this working. i'm still at it.
0
 
LVL 4

Expert Comment

by:havman56
Comment Utility
on the day afetr we chated
i feel there is some difference of  voltages in the LED.
but i am not sure on it!!!

if u get worked done let me know how did u solved taht problem so that i will also get learned
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
>> I've used every combo of data and stop bits i can think of.

The problem is more likely to be related to flow control.  For instance, if hardware flow control is selected and the wrong pin is fixed high or low (sorry, I'm not a hardware guy) then the system will think that the device is saying that it is busy so the system will not send it the data.

That does not explain why the XP system fails while others work... except that on that system some default settings may be in effect.  Also, recall that some DCB-setting commands are simply ignored by some device drivers, so change the default settings via the Device Manager.

One (unrelated) angle of attack would be to use a different serial port; for instance to plug in a cheap PCI card for COM3.

-- Dan

0
 

Author Comment

by:axia
Comment Utility
Pin info: Only the transmit pin is hooked to anything. It's hooked to a wire going in to the device. Here's a description:

Ok, there has been a change now. Forget about the LED. It's updated to have a different output (i can't control how they make the hardware). The setup was much more complicated than i first thought. The output is now a 4-digit 7-segment LED. They have tested this extensivly and they know that the hardware is setup correctly. The device takes my input and depending on the frequency, it decides what to display on the LED display. (I know this sounds like there could be a much easier way to control a 7-segment LED display, but this is a unique situation). The device is quite complicated, but they have demonstated that there is no flaw in the design (except the fact it wasn't originally designed for use with a serial port) I have recieved a description of the hardware. Here it is:

"Our device is basically looking for a 5 volt square wave at a frequency that varies depending on the value you want to display on the LED."

Here's a small table:

Value to Display / Frequency
1000 / 133 Hz
2000 / 266 Hz
4000 / 533 Hz
8000 / 1067 Hz

I read this to mean that to display a value of 4000 on the LED display I have to generate 533 pulses per second over the serial cable. Is that correct?
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
That's utterly fascinating.  Did you try altering the flow control settings?

-- Dan
0
 

Author Comment

by:axia
Comment Utility
I've been using no flow control (none). I've been doing that because the only serial port pin connected is the transmit pin. It's so basic that I don't think flow control would work. Is this correct?
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
That's the point.  The serial port driver may be expecting certain pins to provide certain signals (data set ready and so forth) and it may be refusing to send when such signals are not present.

I remember a technique we used to forcibly blast data to the mode even when it was signalling that it was not ready...  We had to disable Carrier Detect (also called RLSD), otherwise the system would think that the remote modem had hung up and would refuse to send.

What do you get when you call GetCommModemStatus() ?

Also, show me the code that you are using when you call SetCommState().  I think you need to set several flags in the DCB.

-- Dan
0
 

Author Comment

by:axia
Comment Utility
GetCommModemStatus: I get 0 in the DWORD parameter and a return value of 1.

SetCommState: I ripped this out of my code rather quickly. I'm pretty sure it's all correct though.

DCB dcb;
GetCommState(myhandle, &dcb); //myhandle is the COM port handle
dcb.BaudRate = dwBaud; //dwBaud holds the baud rate
dcb.ByteSize = DataBits; //DataBits holds the DataBits value
dcb.fDsrSensitivity = FALSE;
dcb.fOutxCtsFlow = FALSE;
dcb.fOutxDsrFlow = FALSE;
dcb.fOutX = FALSE;
dcb.fInX = FALSE;
SetCommState(myhandle, &dcb); //myhandle is the COM port handle

Could you give me more information on disabling RLSD?

Would this not working be due to a difference between the XP and other Windows version's serial port drivers?
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
try setting fDtrControl to DTR_CONTROL_DISABLE

verify that BaudRate is one of the defined constants (eg, CBR_19200)

try setting fRtsControl to RTS_CONTROL_DISABLE

verify that there is no error returned from the call to SetCommState

>>Would this not working be due to a difference between the XP and other Windows version's serial port drivers?

That's a working hypothesis.  Or it might be related to the combination of driver and actual hardware port.

-- Dan
0
 

Author Comment

by:axia
Comment Utility
I modifed my code to set both of those values.
I made sure the baudrate was valid.
SetCommState returns sucessfully.

There is still nothing.

I doubt it's an issue with the actual serial hardware because this problem has been experienced on every XP machine I have tested.
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Dang, this is a hard one.  I wish I had such an interesting project to work on!

Do you have two COM ports? And if so, is there any difference when you use COM2?

More checking on Google:
What does device Manager say about your COM ports?  Have you tried [Update Driver] and what are the filenames (in case there is some third-party virtual driver involved).

Does the machine have an infrared port?  If so, see if you can turn it off.

Have a hardware guy check that all of the RS232 lines are terminated in the correct state.  I don't think you can get by with just running a single wire.

It seems that there might be a delay between the time you open the port and the time it is available for use.  Place a breakpoint after open, then wait 60 seconds, and then single-step through the Write operation.

Go to "device manager", "mice and pointing devices" and disable "serial pen pointing device".

Try calling EscapeCommFunction with various values before attempting to write to the posrt.

When you call ClearComError, what do you get back in  COMSTAT ?  Before the write and after the write?

When you call GetCommModemStatus, what is the value in dwModemStatus?

-- Dan
0
 

Author Comment

by:axia
Comment Utility
I'm busy at the moment. I will try the things you haev listed above tomorrow. I can tell you that it would be wise to rule out anything specific to my computer. There is not IR port. I have tried it on machines with both 1 (my laptop) and 2 (all the other machines) COM ports. I've tested and the COM port that I select makes no difference. On all of the machines tested the internal serial ports were used. Most had different motherboards (not sure about the serial controller) but there was a great bit of diversity between the test machines. I think this device will eventually be deployed in small quantities and it would be nice if it worked with the default driver.

johanhz said:
"I have just made a simple cable & LED connection (TXD connected to the anode, kathode fixed to ground with a series resistor), and tested with hyperterminal. The Led lights up! (and yes, OS = XP)."

I wonder if he terminated everything. I know so little about the actual device it's sickening but I'll work on getting more info about the connector.
0
 

Author Comment

by:axia
Comment Utility
COM port drivers:
 C:\WINDOWS\System32\DRIVERS\serenum.sys
 C:\WINDOWS\System32\DRIVERS\serial.sys

I tried waiting 1 minute between the open and the write calls and it still doesn't work.

> Go to "device manager", "mice and pointing devices" and disable "serial pen pointing device".
There isn't one listed. Just the normal mouse/pointing device.

I tried calling EscapeCommFunction with various values before attempting to write to the port and the function returned successfully but it didn't help.

> When you call ClearComError, what do you get back in  COMSTAT ?
>Before the write and after the write?
I must be doing this incorrectly because it gives me an access violation. could you post a code snippet?

When I call GetCommModemStatus the value of LPDWORD dwModemStatus is 0x00000000.
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
DWORD dwErrors;
COMSTAT rCS;
BOOL fRet= ClearCommError( hComm, &dwErrors, &rCS);

=-=-=-=-=-=-=-
One other bit of coding that you could try, based on your statement that a VB program can make this work on XP:

Create a dialog-based app and add an ActiveX control named Microsoft Communications Control.  Have the ClassWizard create a wrapper for it (create a control-type variable for it).  You should then be able to use the functions in the wrapper (such as m_ctlComm.SetPortOpen(), etc.  There is a trick with SetOutput() .. you need to create a variant_t value rather than a simple c string.  There is some VB-oriented help avialbel when you are looking at the Properties dialog in the resource editor.  If you get stuck on this, I'll help you work it out (we're running out of things to try...)

-- Dan
0
 

Author Comment

by:axia
Comment Utility
Hmm, I guess i just needed a re-build.
The following results are the same for before and after:
fCtsHold = 0
fDsrHold = 0
fRlsdHold = 0
fXoffHold = 0
fXoffSent = 0
fEof = 0
fTxim = 0
fReserved = 10347
cbInQue = 0
cbOutQue = 0

I'm working on the ActiveX control. I made a wrapper class and control-type variable for it. I added a button to a dialog and set the code to do my operating whenever the button was pressed. From what i could find on the internet I was able to piece the following code together. I'd appreciate help with this code (it's probably pretty messed up):

m_com.GetPortOpen(); //m_com is the control variable
VARIANT data;
CString teststring = "thedatathatiwanttosendtocom1";
data.vt=VT_BSTR;
data.bstrVal=teststring.AllocSysString();
m_com.SetOutput(data);
VariantClear(&var);

---
It compiles fine but when I hit the button it says: "Operation valid only when the port is open"

Thanks!
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
you used GetPortOpen rather the SetPortOpen
-- Dan
0
 

Author Comment

by:axia
Comment Utility
Oops, I changed it to Set. It still doesn't work.
0
 

Author Comment

by:axia
Comment Utility
(No error message, but the device still doesn't work)
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
I see it should be

   SetPortOpen( TRUE );

and check the return code.

Run that code on a Win2K machine to verify that you have working code.  When you have it successfully driving the device on Win2K, try it again on WinXP.  

Also, there are a number of settings that you can try.  Some are available in the control properties (dialog editor) and others are set via member functions.   Look in the file mscomm.h for hints.

Always check the returned status and use Get

Verify that the control thinks it is sending the data... I think there is a command to get the number of bytes waiting in the output Queue: GetOutBufferCount().  Immediately after setting say 1000 bytes, it should be 1000.  Then later, it should be less.  Either way, we have learned something.

-- Dan
0
 

Author Comment

by:axia
Comment Utility
ok, i'll try this.
note: i did use SetPortOpen(TRUE)
0
 

Author Comment

by:axia
Comment Utility
I'll work on those latest suggestions is a little while.
I've been hacking at the VB program for the past few minutes and since it was writeen in VB and used some strange VB installer I was able to peer through several logs to find out that it does use "MSComm32.ocx". That might be helpful to know.
0
 

Author Comment

by:axia
Comment Utility
Sorry for the delay. I just got back from an unscheduled vacation of sorts. I'm back working on this. Thanks for your patience!
0
 
LVL 11

Expert Comment

by:griessh
Comment Utility
Dear

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "DanRollins"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
Comment Utility
Force accepted

** Mindphaser - Community Support Moderator **
0
 
LVL 4

Expert Comment

by:havman56
Comment Utility
Axia

 a big cheat ....



u talked with me and chated with for 2hrs for ur help after getting ur help u never turned up...

i am not saying i had given u solution but i have tried my best to do so.
even dan rollins had tried so no one had given any full correct solution.

ya Dan Rollins also helped him lot . i agreed!!!!!
Dan deserved the points!!!!

axia, the booted coward guy who dread the petty shame to spit on his face .....

ya mindphaser i feel he should be banned in EE for sucha shameful act who got help  by all means and not even
returning back afetr he gets his task finished..

the shameless guy.... my first spit on his face.

his yahoo id is
http://profiles.yahoo.com/there_are_no_normal_names_left


i came to browsing center to help the guy and chated for 2 hrs later no response from him idiot.......


i am very sorry if my words are harsh but he deserved it!

0
 
LVL 6

Expert Comment

by:Mindphaser
Comment Utility
havman56

I am sorry to hear your problems with axia. The last time he logged in was about two months ago, so I am not sure if we ever will hear about him again.

For other cases like that I would suggest to post in the question once you get notified about a reminder like the one griessh posted here. You can always claim that you helped out and we can discuss the process of awarding after that. Unfortunatelly we didn't know that and how you were helping axia. The decision on whom to award the points is purely made by looking at the first reasonable comment. Our major concern is the ongoing discussion here in EE and that's what finally goes into the database.

For your help here in this question I posted a question for you at http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20407169.html but please remember for the future, if you help an asker, we need the solution here in EE, not in a chat room.

Thanks for your feedback

** Mindphaser - Community Support Moderator **
0
 
LVL 4

Expert Comment

by:havman56
Comment Utility
Mindphaser

i feel u took my comments in wrong way ... i am not for points.

i am very sure Dan rollins deserved it than me...

Apart form that with chat , he needed quick solution thats why we chated other wise i wont do chatting to solve problems

I prefer always EE.

Anyway if my comments given some wrong impression sorry for it!

0
 
LVL 6

Expert Comment

by:Mindphaser
Comment Utility
havman56

No, I didn't get your wrong! I understand that it is about the honor to have helped. axia is not responding here anymore and unfortunatelly the only way (except with my words here) to show you how much we appreciate your help is to award you points. I have seen several of your threads where you helped with serial communication and IR problems, so I know that you are an expert in that area.
Please accept those points as our small sign that even if one asker doesn't give you anymore feedback, we are well aware that you folks still trying to help other people with their problems. Nobody has to suffer a loss of points, since they will come out of my pocket and I have no time to ask other questions anyhow :-)

** Mindphaser - Community Support Moderator **
0
 
LVL 4

Expert Comment

by:havman56
Comment Utility
Thanks alot !!!!
very genuine reply which made me more delighted...
great indeed!!!

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now