Calling IowKitGetSerialNumber!!

This is the English forum for all topics related to IO-Warrior. Please post in English only

Moderator: Guido Körber

Post Reply
mhserrano
Posts: 45
Joined: Tue Dec 11, 2007 8:24 pm
Location: Torres Vedras, Portugal

Calling IowKitGetSerialNumber!!

Post by mhserrano »

Hi all,

I´m writing my own program to talk with IOW40 in MFC Visual C++ 6.0.

Until now i´me made a few things but they are working well.

But i cant find any way to fill an Edit Box on MFC with the Serial Number string of IOW40.

The code i´ve writed is:

void CInterfaceSystemDlg::OnPedirSerialNumber()
{
// TODO: Add your control notification handler code here
WCHAR buffer[9];

IOWKIT_HANDLE ioHandle;

IowKitGetSerialNumber(ioHandle, buffer);

m_serial_number.Format("%ws\n", buffer);

UpdateData(FALSE);


}


The compiler gives me no errors, but when i run the program he gives error and the message:

"Debug Assertion Failed

File: strex.cpp

Line: 672"


What am i doing wrong?!

Thanks in advance,

Marco Serrano
User avatar
Christoph Jung
Posts: 670
Joined: Sun Oct 08, 2006 3:43 pm
Location: Germany / Berlin
Contact:

Re: Calling IowKitGetSerialNumber!!

Post by Christoph Jung »

Hi,

Have you used "IowKitOpenDevice()" ?
It is nessesary to get information from the IO-Warrior.

Do it like this:

Code: Select all

	WCHAR buffer[9];
	//CString serial;

	IOWKIT_HANDLE ioHandle = NULL;
	ioHandle = IowKitOpenDevice();

	IowKitGetSerialNumber(ioHandle, buffer);

	m_serial_number.Format("%ws\n", buffer);

	//MessageBox(serial, NULL, MB_OK);

	IowKitCloseDevice(ioHandle);
Abteilung: Softwareentwicklung
Folge uns auf Twitter
Follow us on twitter
mhserrano
Posts: 45
Joined: Tue Dec 11, 2007 8:24 pm
Location: Torres Vedras, Portugal

Re: Calling IowKitGetSerialNumber!!

Post by mhserrano »

Hi, first of all, thanks Christoph for your prompt reply!


I´ve called IowKitOpenDevice() on the section //TODO add extra initialization code. I think this is enough or i must call the function several times as it comes necessary like in this situation?

I´ve done copy/paste your code for my .cpp file and when i recompiled it the same message occured, "debug assertion failed". Even when i tried with MessageBox instead the variable for Edit Box.

Thanks for your help, i dont have much skills on C++ and any suggestions are wellcome!

Bye,

MS
User avatar
Christoph Jung
Posts: 670
Joined: Sun Oct 08, 2006 3:43 pm
Location: Germany / Berlin
Contact:

Re: Calling IowKitGetSerialNumber!!

Post by Christoph Jung »

You must call IowKitOpenDevice() for one time and with one member-variable. Don't use another handle for calling the IOW-Functions.

For example call in the "OnInitDialog()" function "IowKitOpenDevice()" with the member "IOWKIT_HANDLE ioHandle;". Before this you may be call "ioHandle = NULL" to set this variable to protect from asserts.

If you are calling "IOWKIT_HANDLE ioHandle;" in every function this variable will not be the handle of the IO-Warrior !

In another function you may use your code to set the serialnumber into your variable or messagebox.

Code: Select all

 
void CInterfaceSystemDlg::OnPedirSerialNumber(void)
{
  WCHAR buffer[9];
//CString serial;

   IowKitGetSerialNumber(ioHandle, buffer);

   m_serial_number.Format("%ws", buffer);
  //serial.Format("%ws", buffer);
   //MessageBox(serial, NULL, MB_OK);

}
You can test this to set a static-item with a text:

Code: Select all

 
void CInterfaceSystemDlg::OnPedirSerialNumber(void)
{
  WCHAR buffer[9];
  CString serial;

   IowKitGetSerialNumber(ioHandle, buffer);
   serial.Format("%ws", buffer);

   GetDlgItem(IDC_STATIC_SERIAL)->SetWindowText(serial); //IDC_STATIC_SERIAL is the resourcename of the static-item of yours

}
The asseration error will be show where the error will be set. Most it will be an unused or unspecific variable. Try to set all variables to "NULL" before using it.
Abteilung: Softwareentwicklung
Folge uns auf Twitter
Follow us on twitter
mhserrano
Posts: 45
Joined: Tue Dec 11, 2007 8:24 pm
Location: Torres Vedras, Portugal

Re: Calling IowKitGetSerialNumber!!

Post by mhserrano »

Hi again,

Thanks Christoph, your advise to not use ioHandle several times along the program was very useful because i could save a lot of warnings from the compiler. :)

The bad news are the assert failure doesn´t go away!! And i´ve tried with the 2 examples you have show, with the static text and the text being displayed on an edit box. Is it possible to be some UNICODE problem on the compiler?

BTW, i will aprecciate if you can give me some ideas on manipulating the functions IowKitRead() and IowKitWrite(). I´m trying to send/receive information to IOW40, but i cant see no results. For example, i´ve coded a button to send a command to put all leds on (example from API sheet):

void CInterfaceSystemDlg::OnLedsON()
{
// TODO: Add your control notification handler code here
IOWKIT40_IO_REPORT report;

ULONG res;

IOWKIT_HANDLE ioHandle = NULL;

//Write IO pins of IO-Warrior40
report.ReportID = 0;

report.Value = 0; //All LEDS On

res = IowKitWrite(ioHandle, IOW_PIPE_IO_PINS, (PCHAR) &report, IOWKIT40_IO_REPORT_SIZE);

if (res != IOWKIT40_IO_REPORT_SIZE)
{
MessageBox("ReportID not write!", "Error Found!", NULL);
OnCancel();
}

But nothing happens and the messsage box appears all the time i click this button (from the error calling). Obviously there is something wrong.

Thanks in advance,

Marco Serrano
User avatar
Christoph Jung
Posts: 670
Joined: Sun Oct 08, 2006 3:43 pm
Location: Germany / Berlin
Contact:

Re: Calling IowKitGetSerialNumber!!

Post by Christoph Jung »

Hi,
it is possible that the problems goes hand in hand with an unicode-error. If you create the project, you will be asked for unicode (i don't know with VS6).
Without your project I can't check your problems with read/write. You can send me the complete project-folder in a zip (without the .ncb-file and debig-folder). Send the ZIP-File to jung(at)codemercs(dot)com and i will take a look into it.
Abteilung: Softwareentwicklung
Folge uns auf Twitter
Follow us on twitter
mhserrano
Posts: 45
Joined: Tue Dec 11, 2007 8:24 pm
Location: Torres Vedras, Portugal

Re: Calling IowKitGetSerialNumber!!

Post by mhserrano »

Ok,

I´ve send you my project, thanks!

MS
User avatar
Christoph Jung
Posts: 670
Joined: Sun Oct 08, 2006 3:43 pm
Location: Germany / Berlin
Contact:

Re: Calling IowKitGetSerialNumber!!

Post by Christoph Jung »

I have take a look into your project and have found some big problems:
  • 1st.
    Step into the OnInitDialog()-Function, delete "IOWKIT_HANDLE ioHandle;" and set "IoHandle = NULL;"
    Set "IowKitSetTimeout(ioHandle, 2000);" in the code. Without that the read-request will never end if no data will be found.

    2nd.
    Step into your H-File (Interface SystemDlg.h) and set "#include 'iowkit.h'" in the topic. After this place "IOWKIT_HANDLE ioHandle;" into the protectet variables (i.e after HICON hIcon):

    3rd.
    Delete (or recommand) all "IOWKIT_HANDLE ioHandle = NULL;" from all functions in your project ! Also you will never see data from the IO-Warrior.

    4th.
    Write in the OnPedirSerlaiNumber()-Function "UpdateData(FALSE)" at the end. Without that you will never see the serialnumber!

    5th.
    "\n" will not be needed in the Format()-Function.
the variable "res" contains count of te readed bytes, not the bytes itself. If you want to see what is set into the bytes use "report.ReaportID = 0xFF" and "report.Bytes[0...3]" for each byte. Or take a look at "IowKitReadImmediate()" to read data from IO-Pins.

I think you will take a look into the sample-apps.
Abteilung: Softwareentwicklung
Folge uns auf Twitter
Follow us on twitter
mhserrano
Posts: 45
Joined: Tue Dec 11, 2007 8:24 pm
Location: Torres Vedras, Portugal

Re: Calling IowKitGetSerialNumber!!

Post by mhserrano »

Hello,

Thanks Christoph, your advises was very useful to "clean" my code.

But i´ve a few more questions...

1- How can i use function IowKitReadImmediate() to display the IO pins values, for example in an Edit Box? I´m just getting 0 or 1´s with this code:

Code: Select all

void CInterfaceSystemDlg::OnRead() 
{
	// TODO: Add your control notification handler code here
	DWORD bits;

	m_read.Format("%d", IowKitReadImmediate(ioHandle, &bits));

	UpdateData(FALSE);

}
2- I have the led matrix operational with 3 seven segment displays. I want to turn on all this leds (or all leds on board). Wath i must change on my code:

Code: Select all

void CInterfaceSystemDlg::OnLedsON() 
{
	// TODO: Add your control notification handler code here
	
	
	IOWKIT40_IO_REPORT report;

	ULONG res;

	//Write IO pins of IO-Warrior40
	report.ReportID = 0;

	report.Value = 0; //All LEDS On

	res = IowKitWrite(ioHandle, IOW_PIPE_IO_PINS, (PCHAR) &report, IOWKIT40_IO_REPORT_SIZE);

	if (res != IOWKIT40_IO_REPORT_SIZE)
	{
		MessageBox("ReportID not write!", "Error Found!", NULL);
	}


}
Thanks in advance!

MS
Guido Körber
Site Admin
Posts: 2856
Joined: Tue Nov 25, 2003 10:25 pm
Location: Germany/Berlin
Contact:

Re: Calling IowKitGetSerialNumber!!

Post by Guido Körber »

What values are you expecting besides 0 and 1???

Regarding the LED matrix function: ReportID 0 is no ReportID at all
ReportID $15 is used to send data to the LED matrix. Setting a bit to 0 means LED off.
mhserrano
Posts: 45
Joined: Tue Dec 11, 2007 8:24 pm
Location: Torres Vedras, Portugal

Re: Calling IowKitGetSerialNumber!!

Post by mhserrano »

Ok, checked!

More 2 questions:

1 - Is it possible to have special mode functions Led-Matrix and Switch-Matrix operating at the same time?

2 - I know the API dont have support for plug/unplug but is there a way to refresh or make the reset of the program instead we have to close it and re-open if we unplug the USB cable?

Thx,

MS
Guido Körber
Site Admin
Posts: 2856
Joined: Tue Nov 25, 2003 10:25 pm
Location: Germany/Berlin
Contact:

Re: Calling IowKitGetSerialNumber!!

Post by Guido Körber »

LCD and LED matrix are exclusive of each other, key matrix and either display mode can be combined. IOW56 can run all special mode fucntions parallel.
Post Reply