OpenCores
URL https://opencores.org/ocsvn/wishbone_uart_controller/wishbone_uart_controller/trunk

Subversion Repositories wishbone_uart_controller

[/] [wishbone_uart_controller/] [branches/] [software/] [IOcomunicator.cs] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 themassau
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.IO.Ports;
6
namespace WindowsFormsApplication1
7
{
8
    class IOcomunicator
9
    {
10
        protected static SerialPort port1;
11
 
12
 
13
 
14
        public IOcomunicator(string portid, int speed)
15
        {
16
            port1 = new SerialPort(portid, speed, Parity.None, 8, StopBits.One);
17
            port1.Open();
18
            port1.ReadTimeout = 100000000;
19
            port1.DataReceived += new
20
            SerialDataReceivedEventHandler(port_DataReceived);
21
        }
22
         private void port_DataReceived(object sender,
23
         SerialDataReceivedEventArgs e) { // Show all the incoming data in the port's buffer
24
             Console.WriteLine(port1.ReadExisting());
25
         }
26
 
27
         protected void WriteToPort(byte[] buffer,int lenght)
28
         {
29
             port1.Write(buffer, 0, lenght);
30
         }
31
 
32
        public void read(byte adress)
33
        {
34
            Byte[] buffer = new Byte[1];
35
            buffer[0] = adress;
36
            WriteToPort(buffer,1);
37
        }
38
 
39
        public Byte[] topc(int aantalReads)
40
        {
41
            Byte[] buffer = new Byte[aantalReads];
42
            buffer[0] = 0;
43
            WriteToPort(buffer, 1);
44
            for (int i = 0; i < aantalReads; i++)
45
                buffer[i] = Convert.ToByte(port1.ReadByte());
46
            return buffer;
47
        }
48
        public void write(byte adress, byte data)
49
        {
50
            Byte[] buffer = new Byte[2];
51
            buffer[1] = data;
52
            buffer[0] = Convert.ToByte(adress | 128);
53
            WriteToPort(buffer,2);
54
        }
55
 
56
 
57
        public void close()
58
        {
59
            port1.Close();
60
        }
61
    }
62
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.