Esempio n. 1
0
    public static unsafe int Main (string[] args)
    {
	int i,a,j,res,b,c;
	float d;
	byte[] buf1=new byte[libno.davePartnerListSize];

	if (args.Length <1) {
	    usage();
	    return -1;
	}
	fds.rfd=libno.setPort(args[adrPos],"38400",'O');
	fds.wfd=fds.rfd;
	if (fds.rfd>0) { 
	    di =libno.daveNewInterface(fds, "IF1", localMPI, useProto, speed);
	    for (i=0; i<3; i++) {
		if (0==libno.daveInitAdapter(di)) {
		    initSuccess=1;	
		    a= libno.daveListReachablePartners(di,buf1);
		    Console.WriteLine("daveListReachablePartners List length: "+a);
		    if (a>0) {
			for (j=0;j<a;j++) {
			    if (buf1[j]==libno.daveMPIReachable) Console.WriteLine("Device at address: "+j);
			}	
		    }
		    break;	
		} else libno.daveDisconnectAdapter(di);
	    }
	    if (initSuccess==0) {
	        Console.WriteLine("Couldn't connect to Adapter!.\n Please try again. You may also try the option -2 for some adapters.");	
	        return -3;
	    }
	    
	    dc = libno.daveNewConnection(di,plcMPI,0,0);
	    
	    if (0==libno.daveConnectPLC(dc)) {;
		res=libno.daveReadBytes(dc, libno.daveFlags, 0, 0, 16, null);
		if (res==0) {
    		    a=libno.daveGetS32(dc);	
    		    b=libno.daveGetS32(dc);
    		    c=libno.daveGetS32(dc);
		    d=libno.daveGetFloat(dc);
		    Console.WriteLine("PLC FD0: " + a);
		    Console.WriteLine("PLC FD4: " + b);
		    Console.WriteLine("PLC FD8: " + c);
		    Console.WriteLine("PLC FD12: " + d);
		} else 
		    Console.WriteLine("error "+res+" "+libno.daveStrerror(res));
		libno.daveDisconnectPLC(dc);    
	    }	    
	    libno.daveDisconnectAdapter(di);
	} else {
	    Console.WriteLine("Couldn't open serial port "+args[adrPos]);
	    return -1;
	}	
	return 0;
    }
Esempio n. 2
0
    public static unsafe int Main(string[] args)
    {
        int   i, a, j, res, b, c;
        float d;

        byte[] buf1 = new byte[libno.davePartnerListSize];

        if (args.Length < 1)
        {
            usage();
            return(-1);
        }
        fds.rfd = libno.setPort(args[adrPos], "38400", 'O');
        fds.wfd = fds.rfd;
        if (fds.rfd > 0)
        {
            di = libno.daveNewInterface(fds, "IF1", localMPI, useProto, speed);
            for (i = 0; i < 3; i++)
            {
                if (0 == libno.daveInitAdapter(di))
                {
                    initSuccess = 1;
                    a           = libno.daveListReachablePartners(di, buf1);
                    Console.WriteLine("daveListReachablePartners List length: " + a);
                    if (a > 0)
                    {
                        for (j = 0; j < a; j++)
                        {
                            if (buf1[j] == libno.daveMPIReachable)
                            {
                                Console.WriteLine("Device at address: " + j);
                            }
                        }
                    }
                    break;
                }
                else
                {
                    libno.daveDisconnectAdapter(di);
                }
            }
            if (initSuccess == 0)
            {
                Console.WriteLine("Couldn't connect to Adapter!.\n Please try again. You may also try the option -2 for some adapters.");
                return(-3);
            }

            dc = libno.daveNewConnection(di, plcMPI, 0, 0);

            if (0 == libno.daveConnectPLC(dc))
            {
                ;
                res = libno.daveReadBytes(dc, libno.daveFlags, 0, 0, 16, null);
                if (res == 0)
                {
                    a = libno.daveGetS32(dc);
                    b = libno.daveGetS32(dc);
                    c = libno.daveGetS32(dc);
                    d = libno.daveGetFloat(dc);
                    Console.WriteLine("PLC FD0: " + a);
                    Console.WriteLine("PLC FD4: " + b);
                    Console.WriteLine("PLC FD8: " + c);
                    Console.WriteLine("PLC FD12: " + d);
                }
                else
                {
                    Console.WriteLine("error " + res + " " + libno.daveStrerror(res));
                }
                libno.daveDisconnectPLC(dc);
            }
            libno.daveDisconnectAdapter(di);
        }
        else
        {
            Console.WriteLine("Couldn't open serial port " + args[adrPos]);
            return(-1);
        }
        return(0);
    }