LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writefile in kernel32.dll problems

I am attempting to write to a serial port using kernel32.dll. I am apparently doing something wrong with my writefile operation. Can someone please take a look?
Thanks,
Matt Lilley
0 Kudos
Message 1 of 5
(3,808 Views)
I do not know much about how kernel32 works, but you are typecasting TEST as U32 and the library call expects I32.

An aside: but is there any reason why you are not using the VISA serial functions?
0 Kudos
Message 2 of 5
(3,794 Views)
Thanks, but I am still having issues.  See this thread for why I am not using VISA http://forums.ni.com/ni/board/message?board.id=170&message.id=158109#M158109
 
Matt
 
 
0 Kudos
Message 3 of 5
(3,790 Views)
Instead of trying to go through kernel32 which is awkward at the least to talk to a serial port I would try to figure out if Hyperterminal can actually properly talk through your interface as suggested in the other thread. Writing to a serial port is not just calling WriteFile but you also need to setup some seetings of the serial port beforehand. Although your main problem here is probably that the nNumberofBytrsTowrite is not passed by reference (pointer) but as value instead according to the documentation of WriteFile on MSDN. Also the lpOverlapped pointer should be configured as an uInt32 passed by value instead, since you don't want the function to believe there is an overlapped structure it should try to interprete. And while you at it reconfigure the lpBuffer parameter as an array of uInt8 values and wire the output of the String To Byte Array fucntion to this parameter. This way it will also work for strings that are not exactly four bytes long.

Your USB driver seems to not completely behave as a COMM driver should and VISA stumbles over this behaviour. If Hyperterminal can talk through your device driver then VISA may be the trouble indeed but it is still likely that the USB device manufacturer has a new driver version too which might fix this anamoly as well. If Hyperterminal doesn't work either the USB driver is surely and 100% at fault.

Also if Hyperterminal does work I'm sure the guys from VISA development might be interested to get more information about what USB device that is to investigate the cause of the problem, in order to be able to get a bugfix or maybe workaround into the next VISA release.

Rolf Kalbermatter

Message Edited by rolfk on 12-30-2005 11:09 AM

Rolf Kalbermatter
My Blog
Message 4 of 5
(3,766 Views)
Hi,


You convert the string to an I32/U32, and that is wrong. The dll takes a pointer to the string, and you are making a 'pointer' out of the first bytes of the string. So the string "1234" would result in a pointer 0x31323334.


Just wire the string or array to the dll, and configure the dll so the lp input takes a pointer to string or an array.


Regards,


Wiebe.


"MattEE" <x@no.email> wrote in message news:1135779207513-304330@exchange.ni.com...
I am attempting to write to a serial port using kernel32.dll. I am apparently doing something wrong with my writefile operation. Can someone please take a look?
Thanks,
Matt Lilley



serialportwrite.vi:
http://forums.ni.com/attachments/ni/170/158494/1/serialportwrite.vi
0 Kudos
Message 5 of 5
(3,737 Views)