473,569 Members | 2,729 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 1052

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

Similar topics

39
6498
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. When it completes, it can call a success, or a failure function. The names of these success, or failure functions will differ, and I'd like to know...
15
7175
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 can) use a function to pass the table name into the query. Here is the basic form of the Mke Tble query: SELECT TxDate, Amount, Tx_ID,...
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. Example Function1 { int TheArray; Function2(TheArray.ToString(); } Function2 (string parm) { .... In here I would like to be able to convert parm...
2
2184
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 Function GetTasks(Optional ByVal lngUserCode As Long) As ADODB.Recordset
13
4108
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 sense to punch out from managed code to native code (I was using IJW) in order to do some amount of floating point work and, if so, what that certain...
6
7596
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, Karthi
5
7206
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 is. Last time the problem was that "using namespace std" apparently had a "link" class/object defined already. Now I get: error: no matching...
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 structure: Private Structure CstData_type Dim Cst_AZ As DbLong
26
4831
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 about the syntax of calling the same. #include <stdio.h> void fp1()
9
2361
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 its prototype. Let's say for instance : foo.c #include <stdio.h>
0
7694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5504
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.