Click here to Skip to main content
15,914,016 members
Home / Discussions / C#
   

C#

 
Questionprerequisites to learn sharepoint Pin
KrishnaRayalu_Talisetti9-Dec-10 23:23
KrishnaRayalu_Talisetti9-Dec-10 23:23 
AnswerRe: prerequisites to learn sharepoint Pin
Pete O'Hanlon9-Dec-10 23:36
mvePete O'Hanlon9-Dec-10 23:36 
AnswerRe: prerequisites to learn sharepoint Pin
Not Active10-Dec-10 3:35
mentorNot Active10-Dec-10 3:35 
QuestionData exchange with OPC between c# code and RSLinx - Rockwell PLC [modified] Pin
rodrigorodriquez9-Dec-10 23:10
rodrigorodriquez9-Dec-10 23:10 
AnswerRe: Data exchange with OPC between c# code and RSLinx - Rockwell PLC Pin
Pete O'Hanlon9-Dec-10 23:22
mvePete O'Hanlon9-Dec-10 23:22 
GeneralRe: Data exchange with OPC between c# code and RSLinx - Rockwell PLC Pin
Rayh05910-Dec-10 12:41
Rayh05910-Dec-10 12:41 
GeneralRe: Data exchange with OPC between c# code and RSLinx - Rockwell PLC Pin
Pete O'Hanlon11-Dec-10 2:16
mvePete O'Hanlon11-Dec-10 2:16 
GeneralRe: Data exchange with OPC between c# code and RSLinx - Rockwell PLC Pin
rodrigorodriquez12-Dec-10 21:39
rodrigorodriquez12-Dec-10 21:39 
Hello

Sorry for my late reply.
In this case the application is dedicated to the communication with RSLinx.
Here I attach the code where I cut many non intersting lines of code so it will not run if you try.
Then if yo need I can attach the complete version.
Anyway the lines that i am interested in are highlighted.

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Timers;
using RsiOPCAuto;
using System.Windows.Forms;
using System.IO;
using System.Threading;

namespace opc_ali
{
    class Program
    {
        //static Opc.Server LinxOPCServer;

        static RsiOPCAuto.OPCServer RSLinxOPCserver;
        static RsiOPCAuto.OPCGroup RSLinxOPCgroup;
        static RsiOPCAuto.OPCItem RSLinxOPCItem_1;
        static RsiOPCAuto.OPCItem RSLinxOPCItem_2;
        static RsiOPCAuto.OPCItem RSLinxOPCItem_3;
        static RsiOPCAuto.OPCItem RSLinxOPCItem_4;

        static int prec_sec_bl = 0;
        static int prec_millis_bl = 0;
        static int TimeNow_Sec, TimeNow_mSec;
        static int tempo_p, tempo_s, delta;

        static int[] DDE_IN_INT = new int[50];
        static int[] DDE_OUT_INT = new int[50];
        static double[] DDE_IN_DOU = new double[50];
        static double[] DDE_OUT_DOU = new double[50];

        static int numero_word_I;
        static int numero_word_O;
        static int tempo_campionamento;
        static int numero_campioni;
        static int new_line;

        public static void Main(string[] args)
        {
            try
            {
                RSLinxOPCserver = new RsiOPCAuto.OPCServer();
                RSLinxOPCserver.Connect("RSLinx OPC Server", "");
                RSLinxOPCgroup = RSLinxOPCserver.OPCGroups.Add("Prova");
                RSLinxOPCgroup.IsActive = true;
                RSLinxOPCgroup.UpdateRate = 50;
                RSLinxOPCgroup.IsSubscribed = true;

 
                RSLinxOPCItem_1 = RSLinxOPCgroup.OPCItems.AddItem("[ali]Program:scrittura_dati_per_out.dde_OUT_INT[0],L1,C1", 1);
                RSLinxOPCItem_2 = RSLinxOPCgroup.OPCItems.AddItem("[ali]Program:scrittura_dati_per_out.dde_OUT_INT[0],L" + numero_word_I + ",C1", 2);
                RSLinxOPCItem_3 = RSLinxOPCgroup.OPCItems.AddItem("[ali]Program:scrittura_dati_per_out.dde_IN_INT[0],L1,C1", 3);
                RSLinxOPCItem_4 = RSLinxOPCgroup.OPCItems.AddItem("[ali]Program:scrittura_dati_per_out.dde_IN_INT[0],L" + numero_word_O + ",C1", 4);
                Lettura_scrittura_sincrona();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Errore",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        public static void Lettura_scrittura_sincrona()
        {
            int itemcount;
            int i;

            int num_file = 0;
            int num_righe = 1;

            System.Array SyncErrors;
            System.Array SyncValues;
            System.Array SyncErrors2;

            Object SyncQualities = null;
            Object SyncTime = null;

            string fileName;
            string rigafile = "";

            int anno;
            int mese;
            int giorno;

            string cod_file = "";

            new_line = numero_word_I * 10 + 34;
            Int32[] DatiRegistrati = new Int32[numero_word_I];
            byte[] byte_riga = new byte[new_line * numero_campioni];

            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            
            try
            {
                itemcount = RSLinxOPCgroup.OPCItems.Count;
                System.Array SyncServerHandles;
                SyncServerHandles = Array.CreateInstance(System.Type.GetType("System.Int32"), 4);

                System.Array DatiDaInviare;
                DatiDaInviare = Array.CreateInstance(System.Type.GetType("System.Int32"), 1);
                
                for (i = 0; i < itemcount; i++)
                {
                    SyncServerHandles.SetValue(RSLinxOPCgroup.OPCItems.Item(i + 1).ServerHandle, i);
                
                }

                anno = DateTime.Now.Date.Year;
                mese = DateTime.Now.Date.Month;
                giorno = DateTime.Now.Date.Day;

                TimeNow_Sec = DateTime.Now.Second;
                TimeNow_mSec = DateTime.Now.Millisecond;
                tempo_p = (prec_sec_bl * 1000) + prec_millis_bl;
                tempo_s = (TimeNow_Sec * 1000) + TimeNow_mSec;
                delta = tempo_s - tempo_p;
                prec_sec_bl = TimeNow_Sec;
                prec_millis_bl = TimeNow_mSec;

                while (true)
                {

                    num_file += 1;
                    num_righe = 1;
                    cod_file = "_" + anno.ToString() + "_" + mese.ToString() + "_" + giorno.ToString() +
                               "_" + num_file;
                    fileName = "C:\\Archivio_registrazioni_Ali\\registra" + cod_file + ".txt";
                    if (!File.Exists(fileName))
                    {
                        FileStream fs = File.Open(fileName, FileMode.Create, FileAccess.Write);
                        fs.Close();
                    }
                    for (num_righe = 1; num_righe < numero_campioni + 1; num_righe++)
                    {

                        for (i = 0; i < numero_word_I; i++)
                        {
                            DatiRegistrati[i] = 0;
                        }
 
                        RSLinxOPCgroup.SyncRead(1, 1, ref SyncServerHandles, out SyncValues,
                                           out SyncErrors, out SyncQualities, out SyncTime);

                        DatiRegistrati = (Int32[])SyncValues.GetValue(1);

                        TimeNow_Sec = DateTime.Now.Second;
                        TimeNow_mSec = DateTime.Now.Millisecond;


                        rigafile = String.Format("{0:00000}", num_righe);
                        encoding.GetBytes(rigafile).CopyTo(byte_riga, ((num_righe - 1) * new_line) + 0);

                        

                        for (i = 0; i < numero_word_I; i++)
                        {
                            if (DatiRegistrati[i] < 0)
                            {
                                rigafile = String.Format("{0:00000000}", DatiRegistrati[i]);
                                encoding.GetBytes(rigafile).CopyTo(byte_riga, ((num_righe - 1) * new_line) + 32 + (i * 10));
                                rigafile = ";";
                                encoding.GetBytes(rigafile).CopyTo(byte_riga, ((num_righe - 1) * new_line) + 41 + (i * 10));
                            }
                            else
                            {
                                rigafile = String.Format("{0:000000000}", DatiRegistrati[i]);
                                encoding.GetBytes(rigafile).CopyTo(byte_riga, ((num_righe - 1) * new_line) + 32 + (i * 10));
                                rigafile = ";";
                                encoding.GetBytes(rigafile).CopyTo(byte_riga, ((num_righe - 1) * new_line) + 41 + (i * 10));
                            }
                        }
                        rigafile = "\r\n";
                        encoding.GetBytes(rigafile).CopyTo(byte_riga, ((num_righe - 1) * new_line) + new_line - 2);

<big></big>                        <big>for (i = 0; i < numero_word_O; i++)
                        {
                          DatiDaInviare[i] = i;
                        }
                        
                        
                        RSLinxOPCgroup.SyncWrite(3, ref SyncServerHandles, ref DatiDaInviare, out SyncErrors2);</big>                        Thread.Sleep(tempo_campionamento);
                    } //fine ciclo for

                    if (File.Exists(fileName))
                    {
                        File.WriteAllBytes(fileName, byte_riga);
                        rigafile = "";
                    }

                    
                } // fine ciclo while
            }

            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Errore",
                              MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

 
    }
}


Regards
rodrigo

Questioncustom symbol handwriting recognition software Pin
RokudouKaiser9-Dec-10 21:51
RokudouKaiser9-Dec-10 21:51 
AnswerRe: custom symbol handwriting recognition software Pin
Pete O'Hanlon9-Dec-10 22:26
mvePete O'Hanlon9-Dec-10 22:26 
AnswerRe: custom symbol handwriting recognition software Pin
OriginalGriff9-Dec-10 22:27
mveOriginalGriff9-Dec-10 22:27 
JokeRe: custom symbol handwriting recognition software Pin
T M Gray10-Dec-10 9:27
T M Gray10-Dec-10 9:27 
Questionhow to use two appender based on the type in log4net Pin
Joe Rozario9-Dec-10 19:23
Joe Rozario9-Dec-10 19:23 
AnswerRe: how to use two appender based on the type in log4net Pin
Joe Rozario15-Dec-10 20:24
Joe Rozario15-Dec-10 20:24 
QuestionADO.Net Transaction Pin
satsumatable9-Dec-10 18:54
satsumatable9-Dec-10 18:54 
AnswerRe: ADO.Net Transaction Pin
thatraja9-Dec-10 19:48
professionalthatraja9-Dec-10 19:48 
GeneralRe: ADO.Net Transaction Pin
tauruswu9-Dec-10 22:16
tauruswu9-Dec-10 22:16 
AnswerRe: ADO.Net Transaction Pin
PIEBALDconsult10-Dec-10 2:41
mvePIEBALDconsult10-Dec-10 2:41 
QuestionCan't see methods in DLL... why? Pin
michaelsd9-Dec-10 12:10
michaelsd9-Dec-10 12:10 
AnswerRe: Can't see methods in DLL... why? Pin
GlobX9-Dec-10 12:46
GlobX9-Dec-10 12:46 
AnswerRe: Can't see methods in DLL... why? Pin
Luc Pattyn9-Dec-10 13:21
sitebuilderLuc Pattyn9-Dec-10 13:21 
QuestionVisual Studio 2010 Web performance test password encryption question Pin
jboyd1119-Dec-10 10:56
jboyd1119-Dec-10 10:56 
QuestionFTP Connection Pin
MumbleB9-Dec-10 7:43
MumbleB9-Dec-10 7:43 
AnswerRe: FTP Connection Pin
Luc Pattyn9-Dec-10 8:02
sitebuilderLuc Pattyn9-Dec-10 8:02 
GeneralRe: FTP Connection Pin
Sunil G 310-Dec-10 2:04
Sunil G 310-Dec-10 2:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.