943,931 Members | Top Members by Rank

View Poll Results: Can we Communicate with x25 using .Net
MayBe 3 100.00%
Never 0 0%
Voters: 3. You may not vote on this poll

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 3289
  • C# RSS
Nov 24th, 2005
0

How To Interface with x25

Expand Post »
Hi Friends
I am Doing Application to interface with the x25.......
The Company Eiconcard provided the sample code but that is in c language. I want to develop it in c#. Below I write the Code which is equivalent to c Language code but its not working properly.
Plz Help me.............

using System;
using System.Runtime.InteropServices ;
using System.Data.Common ;
using System.Threading;

namespace UdayChat
{
/// <summary>
/// Summary description for MyClass.
/// </summary>
public class MyClass
{
public MyClass()
{
}
public struct x25Data
{
public string Xd_Data;
public int Xd_Len;
}
public struct x25doneinfo
{
public int xi_len;
public string xi_buf;
public int xi_cid;
public int xi_cmd;
public int xi_info;
public int xi_retcode;
[MarshalAs(UnmanagedType.AsAny)] object xi_ref;
};
////////
//public x25doneinfo doneinfo = new x25doneinfo();
public delegate void PostDelgate(ref x25doneinfo doneInfo );
//public const X25NULLFN (void (intPtr)) ;



[MarshalAs(UnmanagedType.FunctionPtr)] PostDelgate post;
const int DATA_SIZE =128;


public static x25Data sUdata = new x25Data() ;
public static x25Data sFacil = new x25Data() ;// size of data buffer */
[DllImport("Ex25.dll")]
public static extern string x25version(char []ss);
[DllImport("Ex25.dll")]
public static extern int x25init(int message,uint uMsg);
[DllImport("Ex25.dll")]
public static extern int x25error();
[DllImport("Ex25.dll")]
public static extern string x25alloc(int DATA_SIZE);
[DllImport("Ex25.dll")]
public static extern int x25exit();
[DllImport("Ex25.dll")]
public static extern int x25xcall(
int Cid,
int X25NOWAIT,
int iPort,
int iInfo,
x25Data sFacil ,
x25Data sUsage ,
string Remote,
string Local,
IntPtr xx);
[DllImport("Ex25.dll")]
public static extern int x25recv(
int Cid,
string cpRecvBuf,
int DATA_SIZE,
int iInfo,
PostDelgate post);
[DllImport("Ex25.dll")]
public static extern int x25send(
int Cid,
string cpRecvBuf,
int DATA_SIZE,
int iInfo,
PostDelgate post);
public string Local ;
public int Cid=0,X25NOWAIT=0,iPort=0,iInfo=0,intFlag=0;
public string Remote,StrError;
public static string cpRecvBuf;
public static char [] argv = new char[50];
public Thread Thread1,Thread2;

public string DispVersion()
{
char [] ss = new char [150] ;
string str;
str = x25version( ss);
return str;
}
public string ExecuteCall(int port,string Data)
{
int intFlag=0,intPort=0;
string strcpSendBuf="",strRecvBuff="";


intFlag = x25init(0,0);
if(intFlag<0)
{
abort_prog_no_x25exit("x25init");
}
/////////// Allocate Buffer.
strcpSendBuf = x25alloc(DATA_SIZE);
if(strcpSendBuf ==null)
{
abort_prog_no_x25exit("x25alloc");
}
strRecvBuff = x25alloc(DATA_SIZE);
if(strRecvBuff ==null)
{
abort_prog_no_x25exit("x25alloc");
}
Form1 fm = new Form1 ();
intPort = port;
sUdata. Xd_Data = Data;
sUdata.Xd_Len = Data.Length;
sFacil.Xd_Data = "1 128";
sFacil.Xd_Len = Data.Length ;
Local = "";
Remote = "4460700";

//////// if(argv[3].ToString().CompareTo("/c")==0)
//////// {
//////// Console.WriteLine ("MODE:\tCALLER\n");
StrError = do_call();
////// }
////// else
////// {
//////////// Console.WriteLine ("MODE:\tListen\n");
//do_Listen();
////// }
return StrError ;
}

public String do_call()
{
StrError = "Calling...";
//////// if(x25xcall( Cid, X25NOWAIT, iPort, iInfo, sFacil , sUdata , Remote, Local, post) < 0)
//////// {
//////// StrError= abort_prog("x25xcall");
//////// return StrError;
//////// }
sFacil.Xd_Data = "1 128";
sFacil.Xd_Len =5;
sUdata.Xd_Data ="uday";
sUdata.Xd_Len = 4;
int intCall =0;
intCall =x25xcall( 2, 0, 2, 0, sFacil , sUdata , "4460700", ".\\uday", IntPtr.Zero ) ;
if( intCall< 0)
{
StrError= abort_prog("x25xcall");
return StrError;
}
do_common();
return StrError ;
}

void do_common()
{
Thread1 = new Thread( new ThreadStart(recvThread));
Thread1.Start();
Thread2 = new Thread( new ThreadStart(recvThread));
Thread2.Start();
}

public void recvThread()
{
Boolean BoolFlag = true;
while(BoolFlag )
{

if(x25recv(Cid,cpRecvBuf,DATA_SIZE,iInfo,post) < 0)
{
abort_prog("x25recv");
}
BoolFlag = false;
}
}
public void sendThread()
{
Boolean BoolFlag = true;
while(BoolFlag )
{

if(x25send(Cid,cpRecvBuf,DATA_SIZE,iInfo,post) < 0)
{
abort_prog("x25recv");
}
BoolFlag = false;
}
}

/////////////////// Error Functions
public string abort_prog_no_x25exit(string CpStr)
{
int intErrorNo=0;
intErrorNo = x25error();
return StrError + intErrorNo.ToString ();
}
public string abort_prog(string cpStr)
{
StrError = StrError + cpStr;
StrError = StrError + "ERROR: " + x25error();
StrError = StrError + setPrgEnd("\n");
return StrError;
}
public string setPrgEnd(string cpStr)
{

StrError = StrError + cpStr;
StrError = abort_prog_x25exit("\nCan't set End Event, Fatal Error\n");
return StrError;
}
string abort_prog_x25exit(string cpStr)
{
StrError = StrError + cpStr;
StrError= StrError + "ERROR:" + x25error();
if(x25exit() < 0)
{
StrError = abort_prog_no_x25exit("x25exit");
}
return StrError ;
}
////////////////// Error End Functions................
}
}

you will get the more info on
http://www.eicon.com/support/trainin...5_Theory&s=150

Thanks in Advance.

Regards,
Uday Shelar.
Attached Files
File Type: zip UdayChat.zip (144.4 KB, 36 views)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
udayshelar is offline Offline
3 posts
since Nov 2005
Jan 30th, 2006
0

Re: How To Interface with x25

Quote originally posted by udayshelar ...
Hi Friends
I am Doing Application to interface with the x25.......
The Company Eiconcard provided the sample code but that is in c language. I want to develop it in c#. Below I write the Code which is equivalent to c Language code but its not working properly.
Plz Help me.............

using System;
using System.Runtime.InteropServices ;
using System.Data.Common ;
using System.Threading;

namespace UdayChat
{
/// <summary>
/// Summary description for MyClass.
/// </summary>
public class MyClass
{
public MyClass()
{
}
public struct x25Data
{
public string Xd_Data;
public int Xd_Len;
}
public struct x25doneinfo
{
public int xi_len;
public string xi_buf;
public int xi_cid;
public int xi_cmd;
public int xi_info;
public int xi_retcode;
[MarshalAs(UnmanagedType.AsAny)] object xi_ref;
};
////////
//public x25doneinfo doneinfo = new x25doneinfo();
public delegate void PostDelgate(ref x25doneinfo doneInfo );
//public const X25NULLFN (void (intPtr)) ;



[MarshalAs(UnmanagedType.FunctionPtr)] PostDelgate post;
const int DATA_SIZE =128;


public static x25Data sUdata = new x25Data() ;
public static x25Data sFacil = new x25Data() ;// size of data buffer */
[DllImport("Ex25.dll")]
public static extern string x25version(char []ss);
[DllImport("Ex25.dll")]
public static extern int x25init(int message,uint uMsg);
[DllImport("Ex25.dll")]
public static extern int x25error();
[DllImport("Ex25.dll")]
public static extern string x25alloc(int DATA_SIZE);
[DllImport("Ex25.dll")]
public static extern int x25exit();
[DllImport("Ex25.dll")]
public static extern int x25xcall(
int Cid,
int X25NOWAIT,
int iPort,
int iInfo,
x25Data sFacil ,
x25Data sUsage ,
string Remote,
string Local,
IntPtr xx);
[DllImport("Ex25.dll")]
public static extern int x25recv(
int Cid,
string cpRecvBuf,
int DATA_SIZE,
int iInfo,
PostDelgate post);
[DllImport("Ex25.dll")]
public static extern int x25send(
int Cid,
string cpRecvBuf,
int DATA_SIZE,
int iInfo,
PostDelgate post);
public string Local ;
public int Cid=0,X25NOWAIT=0,iPort=0,iInfo=0,intFlag=0;
public string Remote,StrError;
public static string cpRecvBuf;
public static char [] argv = new char[50];
public Thread Thread1,Thread2;

public string DispVersion()
{
char [] ss = new char [150] ;
string str;
str = x25version( ss);
return str;
}
public string ExecuteCall(int port,string Data)
{
int intFlag=0,intPort=0;
string strcpSendBuf="",strRecvBuff="";


intFlag = x25init(0,0);
if(intFlag<0)
{
abort_prog_no_x25exit("x25init");
}
/////////// Allocate Buffer.
strcpSendBuf = x25alloc(DATA_SIZE);
if(strcpSendBuf ==null)
{
abort_prog_no_x25exit("x25alloc");
}
strRecvBuff = x25alloc(DATA_SIZE);
if(strRecvBuff ==null)
{
abort_prog_no_x25exit("x25alloc");
}
Form1 fm = new Form1 ();
intPort = port;
sUdata. Xd_Data = Data;
sUdata.Xd_Len = Data.Length;
sFacil.Xd_Data = "1 128";
sFacil.Xd_Len = Data.Length ;
Local = "";
Remote = "4460700";

//////// if(argv[3].ToString().CompareTo("/c")==0)
//////// {
//////// Console.WriteLine ("MODE:\tCALLER\n");
StrError = do_call();
////// }
////// else
////// {
//////////// Console.WriteLine ("MODE:\tListen\n");
//do_Listen();
////// }
return StrError ;
}

public String do_call()
{
StrError = "Calling...";
//////// if(x25xcall( Cid, X25NOWAIT, iPort, iInfo, sFacil , sUdata , Remote, Local, post) < 0)
//////// {
//////// StrError= abort_prog("x25xcall");
//////// return StrError;
//////// }
sFacil.Xd_Data = "1 128";
sFacil.Xd_Len =5;
sUdata.Xd_Data ="uday";
sUdata.Xd_Len = 4;
int intCall =0;
intCall =x25xcall( 2, 0, 2, 0, sFacil , sUdata , "4460700", ".\\uday", IntPtr.Zero ) ;
if( intCall< 0)
{
StrError= abort_prog("x25xcall");
return StrError;
}
do_common();
return StrError ;
}

void do_common()
{
Thread1 = new Thread( new ThreadStart(recvThread));
Thread1.Start();
Thread2 = new Thread( new ThreadStart(recvThread));
Thread2.Start();
}

public void recvThread()
{
Boolean BoolFlag = true;
while(BoolFlag )
{

if(x25recv(Cid,cpRecvBuf,DATA_SIZE,iInfo,post) < 0)
{
abort_prog("x25recv");
}
BoolFlag = false;
}
}
public void sendThread()
{
Boolean BoolFlag = true;
while(BoolFlag )
{

if(x25send(Cid,cpRecvBuf,DATA_SIZE,iInfo,post) < 0)
{
abort_prog("x25recv");
}
BoolFlag = false;
}
}

/////////////////// Error Functions
public string abort_prog_no_x25exit(string CpStr)
{
int intErrorNo=0;
intErrorNo = x25error();
return StrError + intErrorNo.ToString ();
}
public string abort_prog(string cpStr)
{
StrError = StrError + cpStr;
StrError = StrError + "ERROR: " + x25error();
StrError = StrError + setPrgEnd("\n");
return StrError;
}
public string setPrgEnd(string cpStr)
{

StrError = StrError + cpStr;
StrError = abort_prog_x25exit("\nCan't set End Event, Fatal Error\n");
return StrError;
}
string abort_prog_x25exit(string cpStr)
{
StrError = StrError + cpStr;
StrError= StrError + "ERROR:" + x25error();
if(x25exit() < 0)
{
StrError = abort_prog_no_x25exit("x25exit");
}
return StrError ;
}
////////////////// Error End Functions................
}
}

you will get the more info on
http://www.eicon.com/support/trainin...5_Theory&s=150

Thanks in Advance.

Regards,
Uday Shelar.
Dear Uday,
i am also struggling the same code what u did , i need help from u can u tell me the solution, for ex25.dll how to interface that, i am thankful if u told that solution, i need very urgent. my mail id :-yb_bhaskar@yahoo.com . i am waiting for your reply

thanks
bhaskar
Reputation Points: 10
Solved Threads: 0
Newbie Poster
balabhaskar is offline Offline
3 posts
since Jan 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Prevent a registry key from deletion
Next Thread in C# Forum Timeline: How to work with ex25.dll in C#





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC