473,503 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function call with HANDLE or string as parameter, difference

I have some issues with the code, I have managed to solve the problem but does not understand the difference.

This should be part of a boot loader where a external PC gets control over the modbus network and flashes every attached device with new FW.

Func1 is supposed to listen to a "magic" packet and then answer with an init sequence on the MB network to put the current master as slave. The last code snippet is a example of this.

Func2 is supposed to act as the new master in the system and sending new FW out.

The first code example fails as the init sequence is not received at the device.

The seccond code example works.

I can not see the reason why they should have different behaviour.

Expand|Select|Wrap|Line Numbers
  1. void func1(HANDLE hCom) {
  2.     /*
  3.      * Useful code with read/write to hCom
  4.      */
  5. }
  6.  
  7. void func2(HANDLE hCOM) {
  8.     /*
  9.      * Useful code with write to hCom
  10.      */
  11. }
  12.  
  13. int main(int argc, char **argv) {
  14.     HANDLE hCom;
  15.     char* ComPort = argv[1];
  16.     hCom = CreateComPort(ComPort);
  17.     func1(hCom);
  18.     func2(hCom);
  19.     CloseHandle(hCom);
  20. }
  21.  
Expand|Select|Wrap|Line Numbers
  1. void func1(char* ComPort) {
  2.     HANDLE hCom;
  3.     hCom = CreateComPort(ComPort);
  4.  
  5.     /*
  6.      * Useful code with read/write to hCom
  7.      */
  8.  
  9.     CloseHandle(hCom);
  10. }
  11.  
  12. void func2(char* ComPort) {
  13.     HANDLE hCom;
  14.     hCom = CreateComPort(ComPort);
  15.  
  16.     /*
  17.      * Useful code with write to hCom
  18.      */
  19.  
  20.     CloseHandle(hCom);
  21. }
  22.  
  23. int main(int argc, char **argv) {
  24.     char* ComPort = argv[1];
  25.     func1(ComPort);
  26.     func2(ComPort);
  27. }
  28.  
Expand|Select|Wrap|Line Numbers
  1. while (fSuccess == 0) {
  2.     ReadFile(hCom, buffer, sizeof(buffer), &NumberBytesRead, NULL);
  3.     ADUlen = NumberBytesRead;
  4.     if (mb_slave(254, &ADUlen, (unsigned char*) buffer)) {
  5.         NumberBytesToWrite = ADUlen;
  6.         fSuccess = WriteFile(hComMB, buffer, NumberBytesToWrite,
  7.                 &NumberBytesWritten, NULL);
  8.     }
  9. }
  10.  
Oct 22 '10 #1
0 1051

Sign in to post your reply or Sign up for a free account.

Similar topics

39
6477
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
15
7168
by: deko | last post by:
I need a way to create a table with a programmatically defined name. I have a Make Table query that will create the table with the name that I put in the query, but I don't know how to (or if I...
3
2069
by: Alex Munk | last post by:
I would like to be able to pass a 2-dimensional array to a function as a string parameter. In the called function I would like to be able to convert the string back into a 2-dimensional array....
2
2178
by: Binder | last post by:
I am trying to call an ActiveX DLL written in VB6 from my C# app. The function call has a single parameter that is declared optional. How do I call it from C#? The VB function is: Public...
13
4097
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
6
7593
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
5
7196
by: Martin Jørgensen | last post by:
Hello again, Sorry to bother but I guess my C++ book isn't very good since it obviously contains errors so the program code doesn't work with g++. However I don't understand what the problem...
1
442
by: Falko Wagner | last post by:
Hi there, I am currently translating a VB 6.0 application to .NET and have the following problem: The data structure I need to pass to a DLL function call has a structure variable inside its...
26
4823
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
9
2352
by: Yannick | last post by:
Hi everyone - I am not quite sure to understand what is really going on when a function defined in one translation unit calls a function defined in a different translation unit without knowing...
0
7084
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.