|
|
OOPS!!! Sorry, i forgot to mention that. Yes, i need individual data pin control, that's why i downloaded inpout32!! Do you think that PortTalk is better?? And what is the second step?? Do i need to create a driver???? All the implementations that i have seen using linux and one for WinNT create a driver and then use a general degugger program to read or write like gdb!!! But there are two programs that don't use such a driver. One is Tranxbdm 1.6 which is for win95 but it programs certain cpu registers. I want to program all the cpu registers.
|
|
|
|
|
psychegr wrote: Do you think that PortTalk is better??
It doesnt really matter as they both function in the same way. The inpout32.dll has a device driver embedded in its resource section and drops/creates a .SYS file when you load the DLL.
psychegr wrote: And what is the second step?? Do i need to create a driver????
No, you simply start communicating with your MC68HC16 controller board using the _outp, _outpw, _outpd[^] functions.
psychegr wrote: But there are two programs that don't use such a driver. One is Tranxbdm 1.6 which is for win95 but it programs certain cpu registers.
Yes, Linux, Win95, Win98, and WinME allow applications to perform I/O directly to the ports. Operating systems based on the NT kernel are running in protected mode[^] and isolate usermode programs from the hardware.
psychegr wrote: I want to program all the cpu registers.
You can start right now. Just call the _outp function with the hardware address of your LPT1 port which is most often at 0x378 but you need to open the device manager to make sure. After you open the device manager you need to right click on your LPT1 printer port and choose the 'Resource' tab which will show you the I/O range.
Good Luck,
-David Delaune
|
|
|
|
|
Ok thank you David!!
One more question for now. I am using the original c source files from 1992 to write my code. Just a few corrections and it shall work! But i found a driver for winnt that it should help me a lot! What i want to ask is that back in 1992 in the original code there were some timing for the program to work. The author back then used assembly language to implement this. In the winnt version sources that i have the author uses KeStallExecutionProcessor which is from the Windows DDK! I need this in order for my program to work. Should I compile it using the vc++ compiler or the WDK compiler??? With the vc++ compiler i get a lot of errors! I am using vc++ 2008 express!!
Thank you and sorry for asking so many!!! I just don't have someone to guide through this!!
|
|
|
|
|
KeStallExecutionProcessor is a kernelmode function that cannot be accessed from usermode on a NT based operating system. A quick question:
What is the purpose of the KeStallExecutionProcessor calls?
If the purpose is to generate a pulsed signal... you may have problems with timing. Microsoft operating systems based on the NT kernel utilize preemptive multitasking[^] which essentially means that if something more important comes up... such as Sound/Audio or a vast list of other things the OS considers important... your usermode application will be stalled. Executing your application in HIGH_PRIORITY_CLASS[^] might help this situation a little... but not much. Windows is simply not a real-time operating system, your application can still be preempted.
If the purpose of the KeStallExecutionProcessor calls are to simply give time for the MC68HC16 to complete the instructions provided then you can just use the Sleep Function[^].
psychegr wrote: Thank you and sorry for asking so many!!! I just don't have someone to guide through this!!
Not a problem, I enjoy helping.
Best Wishes,
-David Delaune
|
|
|
|
|
Dear David,
I am using inpout32.dll but i always get "error LNK2019: unresolved external symbol _Out32@8 referenced in function....."!!
Same for the "Inp32"!!! I have added he library directory to the project properties and the dll to all possible directories and I have this error. What am I doing wrong??? Can you suggest other driver which will work with my project? I am using VC++ 2008 Express!!
Thank you in advance!
|
|
|
|
|
Hi Padelis,
psychegr wrote: but i always get "error LNK2019: unresolved external symbol _Out32@8 referenced in function....."!! Same for the "Inp32"!!!
Question: Was the old code written for the Borland C/C++ compiler? I believe Out32 is the Borland version of Microsofts modern _outpw[^].
psychegr wrote: Can you suggest other driver which will work with my project?
I always recommend using PortTalk - A Windows NT I/O Port Device Driver.[^]
If you look at our previous chat you will see where I have already recommended using this. The post also contained instructions for using it. Anyway... the problem is probably not inpout32.dll. I believe your problem is calling Borland I/O functions from VC++ 2008 Express. Try changing those Out32 function calls to _outpw and replace Inp32 with inpw.
Make sure you use the correct function for the IN/OUT data size (BYTE,WORD,DWORD). Here is the MSDN reference docs:
_inp, _inpw, _inpd[^]
_outp, _outpw, _outpd[^]
Come back and ask if you have more problems.
Best Wishes,
-David Delaune
|
|
|
|
|
I was thinking to implement a PortTalk like code in my program but i will give it a try like you are suggesting!
Out32 and Inp32 are the functions from the inpout32.dll!!
The original source code was written for Turbo C!!! Is there a site or reference manual to do the convertion from Borland Turbo C to Microsoft Visual C++ 2008 Express???? I think that I will make a huge step with this! I thought that both compilers were the same !!! My fault!!!
I will change all the functions as you are suggesting and I will try to understand what the original author tried to do in Turbo C, so that i can transfer the code to VC++!!!
David you are really helpfull!!! Thank you very much, you are my teacher !!!!
|
|
|
|
|
David,
Do you see any wrong in this code?
I get always the error C2440 "=" cannot convert from "char [64]" to "unsigned char *"!
int do_srec (srecord *where, FILE *infile)
{
int ctr,asize,c;
BYTE *put, s9flag = 0;
do c = fgetc (infile);
while (c != 'S' && c != EOF);
if (c == EOF) return SREC_EOF;
FREAD (infile,where->rectype);
switch (where->rectype)
{
case '0':
asize = 2;
break;
case '1':
case '2':
case '3':
asize = 1 + where->rectype - '0';
break;
case '7':
case '8':
case '9':
asize = 11 - (where->rectype - '0');
s9flag = 1;
break;
default:
return SREC_FORMAT;
}
checksum = 0;
where->reclen = collect (1,&c, infile);
where->address = 0;
for (ctr = asize; ctr; ctr--)
{
where->address <<= 8;
where->address |= collect (1,&where->reclen, infile);
}
put = where->bytes;
for (ctr = where->reclen-1; ctr; )
*put++ = collect (1, &ctr, infile);
collect (1, &where->reclen, infile);
if (checksum != 0xff) return SREC_CHECKSUM;
where->reclen += 4;
return s9flag ? SREC_S9 : 0;
}
The error occurs in the 8th line from the end!
|
|
|
|
|
Hi Padelis,
Sorry for the delayed response. You replied to yourself and I did not recieve notification of the response. Your lucky I checked this thread.
Is this the line giving you trouble?
put = where->bytes;
To cast a pointer to char[64] into a pointer to BYTE you simply need to do:
put = (BYTE *)where->bytes;
|
|
|
|
|
David,
thank you again for one more time !!
The problem was exactly the one you mentioned above and you were right for one more time!
Finally i gave up the idea to compile the original source code and right now i started from the beginning but this time everything is different!
I started with a windows form template and built the GUI for my program. Everything compiles ok!!
Then i started programming the event handlers for the buttons! The "Exit" button works ok, the "Open File" button brings up the openfiledialog box, the "Save File" brings up the savefiledialog box but doesn't create a file and doesn't save anything and finaly the "Connect" button which when pressed executes the routine to connect to the chip! So far the things go as i was planning to!!
Now i have 2 more buttons to program. The first is the "Read Ecu" button which dumps all the code from the chip to a file selected from the "Save File" button. The second one is the "Write Ecu" button which writes the file selected from the "Open File" button to the chip!
The way i am thinking now is different! I include a header file to form1.h file which contains all the functions for the buttons' event handlers! The "Connect" button compiles ok! The problem is with the read and write buttons. When I press the read button my app exits with no crash. What is happening???
Below is the function which is executed when read button is pressed!
int DumpRegisters (void)
{
int Stopped = StopChip ();
unsigned SR, Counter;
LONG Temp;
_cprintf(
"ACCD %04X\tACCM %01X.%04X%04X"
"ACCE %04X\tHR %04X"
"IX %01X %04X\tIR %04X"
"IY %01X %04X\tXMSK %04X"
"IZ %01X %04X\tYMSK %04X"
"SP %01X %04X"
"PC %01X %04X"
"K %04X" ,
(WORD) GetReg (REG_D),
(WORD) GetReg (REG_AM2 & 0xf),
(WORD) GetReg (REG_AM1),
(WORD) GetReg (REG_AM0),
(WORD) GetReg (REG_E),
(WORD) GetReg (REG_H),
(WORD) (GetReg (REG_K) & 0xf00) >> 8,
(WORD) GetReg (REG_IX),
(WORD) GetReg (REG_I),
(WORD) (GetReg (REG_K) & 0xf0) >> 4,
(WORD) GetReg (REG_IY),
(WORD) GetReg (REG_XMYM) >> 8,
(WORD) (GetReg (REG_K) & 0xf),
(WORD) GetReg (REG_IZ),
(WORD) GetReg (REG_XMYM) & 0xff,
(WORD) GetReg (REG_SK),
(WORD) GetReg (REG_SP),
(WORD) GetReg (REG_PK),
(WORD) GetReg (REG_PC),
(WORD) GetReg (REG_K));
_cprintf (" SMHENZVC210S-PK-" NEWLINE "CCR ");
Temp = GetReg (REG_CCR);
SR = 0x8000;
for (Counter = 0; Counter < 16; Counter++)
{
_putch ((Temp & SR) ? '1' : '0');
SR >>= 1;
}
_cputs ( NEWLINE );
if (Stopped) RunChip (0);
return 0;
}
What i need to do is to convert this code to write the data from the chip to a file. GetReg() reads the data from the registers in the chip. If you need more on this i can attach any code you may need! I just don't understand exactly what this function does so that i can convert it!
|
|
|
|
|
Hi Padelis,
I do not see anything wrong with the code you have provided. The GetReg function is probably using the port I/O to read the registers. You need to make sure this GetReg function is working. It might be crashing there.
You should set a breakpoint at the top of this function and execute it in Debug mode. When execution hits the breakpoint use F11 to step into those GetReg calls. Using this method should show you the exact line it is crashing on.
If your not familiar with debugging inside Visual Studio here is a tutorial:
Basic Debugging Features In Visual Studio 2005 [^]
Looks like the tutorial was written for C# .NET applications... but the basic instructions are accurate even for C++ based Visual Studio applications.
Best Wishes,
-David Delaune
|
|
|
|
|
Hi David,
Sorry for not posting for a few days. I was reading for my project! I have got an error free compiled program but i get some errors when i try to run some of the functions. I will post the code where the debugger breaks. I think that it is the va_arg
static long bdm_read (long addr, int pcount, unsigned ResponseSize, long *Where, short cmd, ...)
{
va_list arg;
int err,count;
long response;
long result;
last_addr = addr;
last_rw = 1;
if (!Initted) bdm_error (BDM_FAULT_PORT);
for (err = 3; err; err--)
{
result = 0;
count = pcount;
va_start (arg,cmd);
response = bdm_clk (cmd, CommandBitCount);
while (count--)
if ((response = bdm_clk (va_arg(arg,short), CommandBitCount)) > BDM_NOTREADY) {
if (response == BDM_BERR) bdm_error (BDM_FAULT_BERR);
continue;
}
for (count = ResponseSize; count; count--)
{
while ((response = bdm_clk (BDM_NOP, CommandBitCount)) == BDM_NOTREADY) ;
if (response < BDM_NOTREADY)
{
result <<= 16;
result |= response;
if (Where) *Where++ = response;
}
else
{
if (response == BDM_BERR) bdm_error (BDM_FAULT_BERR);
break;
}
}
if (response > BDM_NOTREADY)
{
if (response == BDM_BERR) bdm_error (BDM_FAULT_BERR);
bdm_clrerror ();
continue;
}
va_end (arg);
break;
}
if (!err) bdm_error (BDM_FAULT_UNKNOWN);
response = bdm_clk (BDM_NOP, CommandBitCount);
if (response == BDM_BERR) bdm_error (BDM_FAULT_BERR);
return result;
}
I can't understand exactly what va_arg does. Thank you for the link of the VS2005 debugger. Really helpful!!
Thank you in advance!
|
|
|
|
|
Hi Padelis,
Good looking code. Some things you need to check:
1.) The line va_arg(arg,short) describes the passed arguments as datatype short. Check your code and make sure that your only sending shorts, you may have accidently passed a BYTE or an int.
2.) It looks like BDM_NOTREADY is the argument terminator value. When the arguments are passed to this function BDM_NOTREADY should be the last value. Such as: "1,2,3,4,5,BDM_NOTREADY". Make sure this is whats happening.
3.) I see a call to response = bdm_clk (cmd, CommandBitCount); outside of the while loop. The result of this call would be removing the first argument from the list without being processed or checked for error. If the first value is BDM_NOTREADY this may cause va_arg to increment past the end. Is this the intended behavior?
Some documentation:
va_arg, va_end, va_start[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
David, may I ask if you are a professional programmer???? Till now you have helped me a lot and you solved all my problems till now! You are great. Wish i had someone to teach me again!!
Once again you were right about the va_arg! I was sending a few BYTES!! My mistake!! As soon as i corrected it, it worked!! But after a while i changed something, don't remember what, and it stopped!
Still scratching my head on what happened! Because i am using some old sources files and updating them, it seems that i will need to completely rewrite some of the functions. The problem appear on the read function which i need to rewrite. I have to read data from parallel and save to a file.! I will not give up till i have it completed!
|
|
|
|
|
Hi Padelis,
psychegr wrote: David, may I ask if you are a professional programmer???? Till now you have helped me a lot and you solved all my problems till now! You are great.
Thanks for the compliments. I have been programming since the early 1980's.
psychegr wrote: Once again you were right about the va_arg! I was sending a few BYTES!! My mistake!! As soon as i corrected it, it worked!! But after a while i changed something, don't remember what, and it stopped!
I recommend that you make a Zip backup each time you have success. I also do this sometimes when I make big changes to projects. Its only 10 seconds to right-click and make a zip file.
psychegr wrote: I will not give up till i have it completed!
Excellent, I like your attitude.
Best Wishes,
-David Delaune
|
|
|
|
|
Early 80s? I was born in 1984!!
I figured out the va_arg mistake now and it is ok.
Currently i have done a lot in this app.
I have managed gain access to parallel port without use of allowio.exe and recognise the hardware!
I have made the basic protocol communications like reset, run and stop!! The mcu connected to the hardware goes into reset, runs and stops.
So far so good! Now i am trying to read the contents of the mcu. The problem is that i have read some bytes from the ecu but all were FFFFs!!! This is not correct! And the time that it does to read 10 addresses is 45 minutes. This is too long. Also my app consists from a Main Form Window with buttons and everything else, and a console window which informs the user with what is happening. When i push the Read button the from window hangs (not responding) but the console window doesn't. The app reads the mcu and this is what it is shown in the console window and when everything finishes the Main Window becomes available again. What could be wrong??? Also is there a way to insert the console window in my Main Window? The console window is the old known console window! Any thoughts??
Also, David have you ever tried to do something similar to what i am doing now?
|
|
|
|
|
Hello guys im trying to learn C and below i have a simple program that keeps reading charachter until the EOF (End of File) Charachter is read.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int c;
while((c = getchar()) != EOF)
{
putchar(c);
}
printf("\n");
printf("%3d \n",EOF);
system("PAUSE");
return 0;
}
Can you please what type of charchter the EOF file is or maybe explain exactly what it is maybe im not understanding. Thank you very much
|
|
|
|
|
Hi,
cdpace wrote: that keeps reading charachter until the EOF (End of File) Charachter is read.
is not accurate. The end-of-file is not stored as some special character; the file or directory has a length stored somewhere, and getchar() returns characters as long as the file length has not been exceeded; when all data has been returned, the special value "EOF" is returned.
So EOF is NOT a character, it is a special integer value outside the regular character range [0,255], and that is exactly why the return type of getchar() isn't char. Usually EOF equals -1.
But that really is an implementation thing, other platforms might use a different special value; the C specification mandates that the symbol EOF works as documented, without fixing a specific value.
|
|
|
|
|
Something I like to add here.
In the DOS/WINDOWS character set, character 26 (^Z)(Control + Z) is assigned as the end of file character for text files.
When we issue the copy con command at the dos prompt, we type text and to terminate we press ^Z.
Take this case.
Consider a binary file of XXX bytes length having the 5th byte as character 26 (Hex: 1A).
Now open the file in text mode - fopen("file", "r");
When you try to read XXX bytes using fread , it will read only 4 characters. (Till character 26).
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
«_Superman_» wrote: In the DOS/WINDOWS character set, character 26 (^Z)(Control + Z) is assigned as the end of file character for text files.
Ctrl+Z is not stored in the file.
«_Superman_» wrote: When we issue the copy con command at the dos prompt, we type text and to terminate we press ^Z.
Ctrl+Z was a special key combination used by copy (and other things borrowed from DEC) to know when to end copying from the console.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
DavidCrow wrote: Ctrl+Z is not stored in the file.
Agreed. But if it does exist in a file, many command will consider that as EOF.
Assume the following file contents -
A B C D E F ^Z G H I J K L
Executing a type command will only output till F.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
I want to have the user click on a MDIchild window frame to resize it, but when you set the frame to WS_THICKFRAME, to get the resizable frame, then the OnNcLButtonDown() event is not seen. I just want to capture the mouse up so I know when the resize should stop. There must be a way to do this.
|
|
|
|
|
In the OnSize handler, check if the left mouse button is down - GetKeyState(VK_LBUTTON)
Now do a SetCapture .
You should now be able to get a WM_LBUTTONUP .
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hi, thanks for the response. I tried this and it does detect the WM_LBUTTONUP, but somehow it lost the ability to stretch the frame. After clicking on the frame dragging the mouse doesn't move the frame.
|
|
|
|
|