hi...
i have c# program, i need this code in java, please help me...... the c# program is as follows..
using System;
using System.IO.Ports;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test_MCP3201_Serial
{
classProgram
{
staticvoid Main(string[] args)
{
constdouble VREF = 5.00;
int b = 0x4000, k = 0;
SerialPort serialPort1 = newSerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
serialPort1.Open();
// Reading the data from ADC MCP3201
serialPort1.RtsEnable = true; // CLK goes low
serialPort1.DtrEnable = false; // CS goes high
// CS goes low allowing the conversion process to be started
serialPort1.DtrEnable = true;
// Processing all 15 CLK pulses
for (int i = 0; i < 15; i++)
{
// CLK goes low
serialPort1.RtsEnable = true;
// Reading appropriate bit into variable b
if (serialPort1.CtsHolding == false) k |= b;
// shift bits of the variable b right to check the next bit
b = b >> 1;
// CLK goes high
serialPort1.RtsEnable = false;
}
// Conversion is done, so CS line goes high
serialPort1.DtrEnable = false;
// Closing the serial porter
serialPort1.Close();
// We need only lower 12 bits of the binary result
k = k & 0xFFF;
// Now the variable k contains the binary result of the conversion.
// The value of k must be transformed into float value which will be
// saved in variable total
int binRes = k;
double total = Convert.ToDouble(binRes);
// Calculating the final result
total = VREF / 4096 * total;
// Outputting the data on to screen
Console.WriteLine("ADC result: {0}", total);
}
}
i have c# program, i need this code in java, please help me...... the c# program is as follows..
using System;
using System.IO.Ports;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test_MCP3201_Serial
{
classProgram
{
staticvoid Main(string[] args)
{
constdouble VREF = 5.00;
int b = 0x4000, k = 0;
SerialPort serialPort1 = newSerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
serialPort1.Open();
// Reading the data from ADC MCP3201
serialPort1.RtsEnable = true; // CLK goes low
serialPort1.DtrEnable = false; // CS goes high
// CS goes low allowing the conversion process to be started
serialPort1.DtrEnable = true;
// Processing all 15 CLK pulses
for (int i = 0; i < 15; i++)
{
// CLK goes low
serialPort1.RtsEnable = true;
// Reading appropriate bit into variable b
if (serialPort1.CtsHolding == false) k |= b;
// shift bits of the variable b right to check the next bit
b = b >> 1;
// CLK goes high
serialPort1.RtsEnable = false;
}
// Conversion is done, so CS line goes high
serialPort1.DtrEnable = false;
// Closing the serial porter
serialPort1.Close();
// We need only lower 12 bits of the binary result
k = k & 0xFFF;
// Now the variable k contains the binary result of the conversion.
// The value of k must be transformed into float value which will be
// saved in variable total
int binRes = k;
double total = Convert.ToDouble(binRes);
// Calculating the final result
total = VREF / 4096 * total;
// Outputting the data on to screen
Console.WriteLine("ADC result: {0}", total);
}
}