I've been trying to compile this program and tried to make edits according to my understanding of the error message that increased the amount of errors. This is the 2nd VHDL code I've ever written and I'm not sure what more I can do
this is the code:
entity maashro3o is
port (Q: out bit_vector (0 to 7);
A: in bit_vector(2 down to 0);
en: in bit);
end maashro3o;
architecture maashro3o of maashro3o is
begin
process(A, en)
begin
if (en = "1")
then
if (A = "000")
then
Q <= "10000000";
else if (A = "001") then
Q <= "01000000";
else if (A = "010") then
Q <= "00100000";
else if (A = "011") then
Q <= "00010000";
else if (A = "100") then
Q <= "00001000";
else if (A = "101") then
Q <= "00000100";
else if (A = "110") then
Q <= "00000010";
else if (A = "111") then
Q <= "00000001";
END If;
else
Q <= "00000000";
End If;
end process;
end maashro3o
Update
I changed else if to elsif and else respectively.
I tried to remove then from else but I'm getting similar errors
entity maashro3o is
port (Q: out bit_vector (0 to 7);
A: in bit_vector(2 downto 0);
en: in bit);
end maashro3o;
architecture maashro3o of maashro3o is
begin
process(A, en)
begin
if (en = '1')
then
if (A = "000")
then
Q <= "10000000";
elsif (A = "001") then
Q <= "01000000";
else (A = "010") then
Q <= "00100000";
elsif (A = "011") then
Q <= "00010000";
else (A = "100") then
Q <= "00001000";
elsif (A = "101") then
Q <= "00000100";
else (A = "110") then
Q <= "00000010";
elsif(A = "111") then
Q <= "00000001";
END If;
else
Q <= "00000000";
End If;
end process;
end maashro3o;
You need to change all the elses inside the block begins with
if (A="000") then
.
.
.
end if;
There is no "else if" keyword in VHDL. Use "elsif". When coding an if-else statement with multiple conditions, you should not write else after elsif or vice versa. You can not use them both.
"else" keyword does not declare a specific statement. It is used for checking only one condition and doing something when condition is not satisfied.
Also when writing a VHDL code, don't forget to include the libraries you will need and may be need.
Corrected code is given below.
library ieee;
use ieee.std_logic_1164.all;
entity maashro3o is
port (Q: out bit_vector (0 to 7);
A: in bit_vector(2 downto 0);
en: in bit);
end maashro3o;
architecture maashro3o of maashro3o is
begin
process(A, en)
begin
if (en = '1') then
if (A = "000") then
Q <= "10000000";
elsif (A = "001") then
Q <= "01000000";
elsif (A = "010") then
Q <= "00100000";
elsif (A = "011") then
Q <= "00010000";
elsif (A = "100") then
Q <= "00001000";
elsif (A = "101") then
Q <= "00000100";
elsif (A = "110") then
Q <= "00000010";
elsif(A = "111") then
Q <= "00000001";
end if;
else
Q <= "00000000";
end if;
end process;
end maashro3o;
Why do you want to use if else statements only, since decoder is a combinational logic you can use case statement to design the logic, it will be more appropriate.
I'm trying to make a counter that sends out a carry signal after every 64 clock pulses. When I try to synthesize the code shown below, (in Vivado) I get the following error,
Else clause after check for clock not supported.
(On the line signaled with the '!!')
I did something very similar in a different project and I did not get any error there, so I don't really get what's wrong. Any help?
entity refresh_counter is
port( CLK : in STD_LOGIC;
CLR : in STD_LOGIC;
CARRY : out STD_LOGIC);
end refresh_counter;
architecture Behavioral of refresh_counter is
begin
process(CLK)
variable tel : integer;
begin
if (CLK'event and CLK = '1') then
if CLR = '1' then
tel := 0;
end if;
else
if (tel < 63) then !!
tel := tel + 1;
else
CARRY <= '1';
tel := 0;
end if;
end if;
end process;
end Behavioral;
As mentioned by #scary_jeff in the comments section, your else doesn't make sense as you cannot practically implement not at rising edge. Here is an implementation that will do the job.
The process has two variables n_carry and n_tel. You can treat them like the combinational output of the FSM. On the clock's rising edge, these two variables are transferred to carry and tel respectively.
In the case CLR is high, 0 will be transferred instead.
The n_carry and n_tel logic is implemented combinationally in hardware. It takes tel as an input and the decision making has been coded in the if-elsif-else sequence in the process.
library std;
library ieee;
use ieee.std_logic_1164.all;
entity refresh_counter is
port( CLK : in STD_LOGIC;
CLR : in STD_LOGIC;
CARRY : out STD_LOGIC);
end refresh_counter;
architecture Behavioral of refresh_counter is
signal tel: integer := 0;
begin
process(CLK, CLR, tel)
variable n_tel: integer := 0;
variable n_carry: STD_LOGIC := '0';
begin
if (tel < 63) then
n_carry := '0';
n_tel := tel + 1;
elsif (tel = 63) then
n_carry := '1';
n_tel := 0;
else
-- This case should never arise in practice
n_carry := '0';
n_tel := 0;
end if;
if (CLK'event and CLK = '1') then
if CLR = '1' then
tel <= 0;
CARRY <= '0';
else
tel <= n_tel;
CARRY <= n_carry;
end if;
end if;
end process;
end Behavioral;
I search google and couldn't find anything that really helped me IBM website show Informix 11.5 and up functions, like if they have stop supporting 9.52C1 or something. Hence the reason I am here.
As the topic stated I'm using Informix 9.52C1. I got this information using the SQL:
SELECT owner FROM systables WHERE TABNAME= ' VERSION';
I'm not sure if the replace function is even supported because when I execute the statement:
SELECT col1, REPLACE('r','p','poster') as col2 FROM table;
The column col2 contains just the letter 'r' however no error was thrown although I used the REPLACE() function.
I know the escape characters (CRLF) can be found using the "\r\n" escape format because this SQL worked accordingly:
SELECT * FROM table WHERE col1 LIKE '%\r\n%';
Note: I used the above SQL to retrieve the version number as I only had access via a client DB application. If however you have access to the actual host running the informix DB server I'm sure there is some command arguement to resolve the version maybe the defualt linux --version or -v arguement with the db server application.
And this indeed returned only the records that contained CRLF.
My main job is to place a backslash in front of CR and LF as I am migrating data from Informix 9.52C1 to a PostgreSQL database. I'm planning to use the COPY function to load the data to the PostgreSQL database and the COPY function works in this manner as I have done a test record. My dilemma is extracting the data from Informix in the correct format. Can anyone assist with this issue?
I have tried:
SELECT REPLACE('\\\r\\\n','\r\n',col1) as description FROM table;
However this didn't work I believe due to the replace function, as I have mention I am not sure if the replace function is available in this Informix version.
Thanks in advance,
jerg
P.S. None of the functions ASCII(),CHAR() and CHR() worked either. Some sites suggested these function. But as far as I can see the functions CHR() & ASCII() was implemented in verison 11.5+. This post suggested the functions.
To migrate data between databases you can use JDBC drivers (I use Jython, but Java or other language which can use JDBC driver will be ok) and then SELECT ... from source database (Informix) and INSERT ... just read data into destination (PostgreSQL). With BatchInsert or PreparedStatement it is really fast. In my code it looks like:
insert_str = 'INSERT INTO ' + table_name + ' (' + column_names + ') VALUES (' + question_marks + ')'
insert_stmt = db_to.prepareStatement(insert_str)
...
pstm2 = db_from.createStatement()
rs_in = pstm2.executeQuery('SELECT %s FROM %s %s' % (column_names, table_name, order_str))
...
while (rs_in.next()):
for i in range(1, col_count + 1):
insert_stmt.setObject(i, rs_in.getObject(i))
Of course you must take care of errors, auto commit, fetch size etc. but I think it is worth your effort.
Your idea with COPY ... is also good. Do you save output from Informix in text file? If it is in text file you can simply correct text file before importing it to PostgreSQL.
I don't recognize the version 9.52C1. An Informix version might be 9.52.UC1 — with a choice from U, F, W, H, T for the first letter. But then again, the main version numbers were 9.00..9.03, 9.10..9.16, 9.20, 9.21, 9.30, 9.40, 10.00, 11.10, 11.50, 11.70, 12.10 — a sequence which doesn't include a 9 and a 5 in a single version. Well, in many ways, it doesn't matter; any version 9.x has been out of support for most of a decade, if not longer, and shouldn't still be in use.
Assuming that an upgrade to a modern version of Informix is not in the cards, you are stuck with implementing your own functions. To do the job, you'd do best to implement them in C and install them as a package of UDRs (user-defined routines) in a shared library. That would give you the best performance. Assuming that's not feasible (I don't have a set of such functions on hand, but it shouldn't be hard to write them), then you have to fall back on SPL (stored procedure language) routines. These are not fast because of the limitations of SPL w.r.t substring operations — specifically, the built-in substring operations with [] notation do not accept variables as subscripts. That's really painful, to be polite about it.
Here's a version of char_at which fetches a single character at a given position in a string of up to 255 characters:
-- #(#)$Id: char_at.spl,v 1.1 1999/05/17 23:59:59 jleffler Exp $
--
-- CHAR_AT stored procedure, to return character at given position in string
--
-- Author: J Leffler
-- Date: 1999-05-17
CREATE PROCEDURE char_at(str VARCHAR(255), pos SMALLINT) RETURNING CHAR(1);
DEFINE c CHAR(1);
IF pos > LENGTH(str) OR pos <= 0 THEN
LET c = NULL;
ELIF pos <= 16 THEN
IF pos = 1 THEN LET c = str[ 1];
ELIF pos = 2 THEN LET c = str[ 2];
ELIF pos = 3 THEN LET c = str[ 3];
ELIF pos = 4 THEN LET c = str[ 4];
ELIF pos = 5 THEN LET c = str[ 5];
ELIF pos = 6 THEN LET c = str[ 6];
ELIF pos = 7 THEN LET c = str[ 7];
ELIF pos = 8 THEN LET c = str[ 8];
ELIF pos = 9 THEN LET c = str[ 9];
ELIF pos = 10 THEN LET c = str[10];
ELIF pos = 11 THEN LET c = str[11];
ELIF pos = 12 THEN LET c = str[12];
ELIF pos = 13 THEN LET c = str[13];
ELIF pos = 14 THEN LET c = str[14];
ELIF pos = 15 THEN LET c = str[15];
ELIF pos = 16 THEN LET c = str[16];
END IF;
ELIF pos <= 32 THEN LET c = char_at(str[ 17, 32], pos - 1 * 16);
ELIF pos <= 48 THEN LET c = char_at(str[ 33, 48], pos - 2 * 16);
ELIF pos <= 64 THEN LET c = char_at(str[ 49, 64], pos - 3 * 16);
ELIF pos <= 80 THEN LET c = char_at(str[ 65, 80], pos - 4 * 16);
ELIF pos <= 96 THEN LET c = char_at(str[ 81, 96], pos - 5 * 16);
ELIF pos <= 112 THEN LET c = char_at(str[ 97,112], pos - 6 * 16);
ELIF pos <= 128 THEN LET c = char_at(str[113,128], pos - 7 * 16);
ELIF pos <= 144 THEN LET c = char_at(str[129,144], pos - 8 * 16);
ELIF pos <= 160 THEN LET c = char_at(str[145,160], pos - 9 * 16);
ELIF pos <= 176 THEN LET c = char_at(str[161,176], pos - 10 * 16);
ELIF pos <= 192 THEN LET c = char_at(str[177,192], pos - 11 * 16);
ELIF pos <= 208 THEN LET c = char_at(str[193,208], pos - 12 * 16);
ELIF pos <= 224 THEN LET c = char_at(str[209,224], pos - 13 * 16);
ELIF pos <= 240 THEN LET c = char_at(str[225,240], pos - 14 * 16);
ELIF pos <= 255 THEN LET c = char_at(str[241,255], pos - 15 * 16); -- Note asymmetry in upper bound!
ELSE LET c = NULL; -- Not reached!
END IF;
RETURN c;
END PROCEDURE;
Handling general substrings and the like is similarly painful. I've never gone to the effort of building even a semi-performant SPL implementation of SUBSTR. It is far, far better to upgrade to a version of Informix that has the support built-in.
CHR() and ASCII()
The CHR(). ASCII() functions can be simulated with:
-- #(#)$Id: chr.sql,v 1.2 2008/09/19 18:48:37 jleffler Exp $
--
-- #(#)Procedure CHR() - return character corresponding to integer
CREATE PROCEDURE chr(i INTEGER) RETURNING CHAR(1) AS result;
DEFINE c CHAR;
IF i < 0 OR i > 255 THEN
RAISE EXCEPTION -746, 0, 'CHR(): integer value out of range 0..255';
END IF;
IF i = 0 OR i IS NULL THEN
LET c = NULL;
ELSE
SELECT chr INTO c FROM ascii WHERE val = i;
END IF;
RETURN c;
END PROCEDURE;
-- #(#)$Id: ascii.sql,v 1.2 2008/09/19 18:40:19 jleffler Exp $
--
-- Procedure ASCII - returning integer corresponding to character.
-- Misnomer: it works on any single-byte character.
CREATE PROCEDURE jl_ascii(C CHAR) RETURNING INT AS result;
DEFINE i INTEGER;
IF c IS NULL THEN
LET i = 0;
ELSE
SELECT val INTO i FROM ascii WHERE chr = c;
END IF;
RETURN i;
END PROCEDURE;
which requires a table:
-- #(#)$Id: asciitbl.sql,v 1.2 2005/03/30 17:51:12 jleffler Exp $
--
-- #(#)Create ASCII Table (for ASCII and CHR functions).
CREATE TABLE ascii
(
val INTEGER NOT NULL UNIQUE CONSTRAINT u1_ascii,
chr CHAR(1) NOT NULL UNIQUE CONSTRAINT u2_ascii
);
REVOKE ALL ON ascii FROM PUBLIC;
GRANT SELECT ON ascii TO PUBLIC;
and the data to go in it — 255 lines such as:
…
32|
33|!
34|"
35|#
36|$
37|%
38|&
39|'
40|(
…
64|#
65|A
66|B
67|C
68|D
69|E
…
You should be able to find a copy of this code at the IIUG under the name ascii.
I'm writing a VBScript that searches the Active Directory for a computer object. If the object does not exist or exists and is in the correct OU, then it should run a separate script that creates/joins the computer to the AD.
ObjExist_CorrectOU_7 = Null
ObjExist_CorrectOU_10 = Null
If compare = True Then
Win7_OU = "OU=DisallowRDP,OU=64Bit,OU=Win8"
Win10_OU = "OU=DisallowRDP,OU=64Bit,OU=Win10"
For x = 16 To 46
If Asc(Mid(objRS.Fields("distinguishedName"), x, 1)) = Asc(Mid(Win7_OU, (x - 15), 1)) Then
ObjExist_CorrectOU_7 = True
Else
ObjExist_CorrectOU_7 = False
End If
Next
For y = 16 To 46
If Asc(Mid(objRS.Fields("distinguishedName"), y, 1)) = Asc(Mid(Win10_OU, (y - 15), 1)) Then
ObjExist_CorrectOU_10 = True
Else
ObjExist_CorrectOU_10 = False
End If
Next
End If
If ObjExist_CorrectOU_7 = True Then
WScript.Echo "TRUE"
End If
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
filename = "C:\programdata\dell\kace\k2000_deployment_info.conf"
Win7_Deployment = "deployment_name=Windows 7 x64 with SP1, join AD"
Win10_Deployment = "deployment_name=Development Windows 10 (x64), join AD"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filename)
Do While Not f.AtEndOfStream
If ((f.ReadLine = Win7_Deployment) Or ((f.ReadLine = Win7_Deployment) And (ObjExist_CorrectOU_7 = True))) Then
WScript.Echo "IT WORKED!"
'objShell.Run "JoinAD_Win7.vbs"
Exit Do
End If
On Error Resume Next
Loop
f.Close
Set g = fso.OpenTextFile(filename)
Do While Not f.AtEndOfStream
If ((g.ReadLine = Win10_Deployment) Or ((g.ReadLine = Win10_Deployment) And (ObjExist_CorrectOU_10 = True))) Then
'objShell.Run "JoinAD_Win10.vbs"
WScript.Echo "IT WORKED AGAIN!"
Exit Do
End If
On Error Resume Next
Loop
g.Close
Set objShell = Nothing
The problem I'm running into is that the two If..Then statements execute every time, even though I know the conditions are absolutely NOT being met.
Does it have to do with my use of Or and And?
Your question does not satisfy Minimal, Complete, and Verifiable example criteria. However, at first sight: read On Error Statement and ReadLine Method and Working with Files documentation.
Do While Not f.AtEndOfStream
''' ↓ this `ReadLine` reads every uneven line i.e. the 1st, 3rd, 5th, …
If ((f.ReadLine = Win7_Deployment) Or ((f.ReadLine = Win7_Deployment) And (ObjExist_CorrectOU_7 = True))) Then
''' this one reads every even line ↑ i.e. the 2nd, 4th, 6th, …
WScript.Echo "IT WORKED!"
'objShell.Run "JoinAD_Win7.vbs"
Exit Do
End If
On Error Resume Next ' this causes that script continues on line next to IF … THEN
' in case of uneven records in file.
' i.e. runtimme error "Input past end of file"
Loop
Use something like
Do While Not f.AtEndOfStream
sReadLine = f.ReadLine
If ((sReadLine = Win7_Deployment) Or ((sReadLine = Win7_Deployment) And (ObjExist_CorrectOU_7 = True))) Then
WScript.Echo "IT WORKED!"
'objShell.Run "JoinAD_Win7.vbs"
Exit Do
End If
''' get rid of `On Error Resume Next` statement at all
Loop
And what about Do While Not f.AtEndOfStream followed up by g.ReadLine? Use either f or g (the same TextStream object in both)…
So I am trying to split characters a certain way.
If I provide this string:
text (text (adsf (asdfasdfjkl) asdfjlkasdjf) stuff) (morestuff stuff)
I want it to split it into:
['text', '(text (adsf (asdfasdfjkl) asdfjlkasdjf) stuff)', '(morestuff stuff)']
Code I had:
def pair_char(left, right, start, text, exclusive=False, verbose=False):
package = []
for e, c in enumerate(text):
left_c = right_c = 0
if text[e] == left:
left_c += 1
marker = start = e
while text[marker+1] != right or left_c > right_c:
marker += 1
if verbose:
print left_c, right_c, text[marker], left, right, text[marker]==left, text[marker]==right
if marker+1 >= len(text):
break
if text[marker] == left_c:
print "left_c"
left_c += 1
if text[marker] == right_c:
print "right_c"
right_c += 1
end = marker
if exclusive:
package.append(text[start+1:end])
else:
package.append(text[start:end+1])
e = end
package = "".join(package)
return package
Any suggestions?