java program

Thread Starter

vishnumoorthy

Joined May 1, 2011
1
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);
}
}
 

WBahn

Joined Mar 31, 2012
30,082
But he gave you a link to a translator that would do the conversion for you. Assuming the translator does a good job, why would you have to know anything about C#?
 

kubeek

Joined Sep 20, 2005
5,795
I am also sorry i cant change this code into Java code as i do not know anything about C#...
This thread is over two years old. I don´t see any purpose in replying to it, or even trying to translate said code over again. Is this some kind of school assignment?
If you got some own code that you need to translate, why don´t you make your own thread?
 

sirch2

Joined Jan 21, 2013
1,037
There are around 20 lines of actual code there and they would appear to be well commented, just code it. C# syntax is pretty similar to Java so the basics should not present a problem. For the serial port see javax.comm.SerialPort and /or google "Java Serial Port"
 

WBahn

Joined Mar 31, 2012
30,082
This thread is over two years old. I don´t see any purpose in replying to it, or even trying to translate said code over again. Is this some kind of school assignment?
If you got some own code that you need to translate, why don´t you make your own thread?
Good observation. I assumed the response I was replying to came from the OP.
 

arnavkumar

Joined Oct 30, 2013
4
This thread is over two years old. I don´t see any purpose in replying to it, or even trying to translate said code over again. Is this some kind of school assignment?
If you got some own code that you need to translate, why don´t you make your own thread?
Sorry for doing this stupid thing, as i am new with the forum so i will take care of its in future.
 
Top