ok well i did alot of stuff and this seems to send stuff but no idea if its sending it correctly/throwing errors.
first:
in .NET Compact Framework I found a way of writing to the COM port directly, giving it "COM3:" with the colon, seems to send signals BUT when you flush the filestream OR close the filestream, it gives me a blank IOException.
So what I did, following your advice was to use the CreateFile() and then got the API's for WriteFile() and CloseHandle().
Now, I seem to be getting a handle, writing to it and closing it fine but of course its unmanaged (correct?). I am developing this in C# .NET Compact Framework 2.0.
this is the code I have, no idea if you will understand it so please bear with me:
Code:
//import libraries:
[DllImport("Coredll.dll", SetLastError=true)]
static extern IntPtr CreateFile(
string filename,
[MarshalAs(UnmanagedType.U4)]FileAccess fileaccess,
[MarshalAs(UnmanagedType.U4)]FileShare fileshare,
int securityattributes,
[MarshalAs(UnmanagedType.U4)]FileMode creationdisposition,
int flags,
IntPtr template);
[DllImport("Coredll.dll", SetLastError = true)]
static extern IntPtr WriteFile(
IntPtr fFile,
Byte[] lpBuffer,
UInt32 nNumberOfBytesToWrite,
out UInt32 lpNumberOfBytesWritten,
IntPtr lpOverlapped);
[DllImport("Coredll.dll", SetLastError = true)]
static extern bool CloseHandle(
IntPtr hObject
);
Above: code to import libraries and the functions
Code:
//createfile and writefile()
IntPtr handle = CreateFile("COM3:", FileAccess.Write, FileShare.Write, 0, FileMode.Create, 0, IntPtr.Zero);
if (handle != IntPtr.Zero)
{
string test = "hi";
byte[] some = System.Text.ASCIIEncoding.ASCII.GetBytes(test);
uint sent = 0;
IntPtr ptrUWO = IntPtr.Zero;
WriteFile(handle, some, (uint)some.Length, out sent, ptrUWO);
CloseHandle(handle);
}
Above: code to createfile() and writefile() and closefile()
Is this correct?
I have also just found out that when it starts to send signals, I get the error :
1359
which is an internal error - any ideas?